Skip to content

Instantly share code, notes, and snippets.

@LucGosso
Last active December 20, 2018 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LucGosso/822b6e25d954c40117008c062ced7e67 to your computer and use it in GitHub Desktop.
Save LucGosso/822b6e25d954c40117008c062ced7e67 to your computer and use it in GitHub Desktop.
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