Last active
December 20, 2018 12:20
-
-
Save LucGosso/822b6e25d954c40117008c062ced7e67 to your computer and use it in GitHub Desktop.
How to customize TinyMCE at runtime https://devblog.gosso.se/?p=824
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using EPiServer.Core; | |
using EPiServer.Shell.ObjectEditing.EditorDescriptors; | |
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
namespace Gosso.Episerver.Business.EditorDescriptors | |
{ | |
[EditorDescriptorRegistration(TargetType = typeof(XhtmlString), EditorDescriptorBehavior = EditorDescriptorBehavior.PlaceLast)] | |
public class CustomXhtmlStringEditorDescriptor : EditorDescriptor | |
{ | |
public override void ModifyMetadata(EPiServer.Shell.ObjectEditing.ExtendedMetadata metadata, | |
IEnumerable<Attribute> attributes) | |
{ | |
if (HttpContext.Current.User.IsInRole("Bloggers")) // do your own logic | |
{ | |
if (metadata.EditorConfiguration["settings"] is Dictionary<string, object> settings) | |
{ | |
var toolbarList = ((IEnumerable) settings["toolbar"]).Cast<string>().ToList(); | |
if (toolbarList.Count >= 1) | |
toolbarList[0] = | |
"bold italic strikethrough styleselect | epi-link image epi-image-editor | customfaktabuttonplugin customimagebuttonplugin | bullist numlist | removeformat | searchreplace fullscreen"; | |
if (toolbarList.Count >= 2) toolbarList[1] = ""; | |
if (toolbarList.Count >= 3) toolbarList[2] = ""; | |
settings["toolbar"] = toolbarList; | |
settings["menubar"] = "false"; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment