Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to customize TinyMCE at runtime https://devblog.gosso.se/?p=824
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