Skip to content

Instantly share code, notes, and snippets.



Last active Oct 9, 2016
What would you like to do?
Different editor tool buttons for normal editors and administrators. Read more over at my blog:
using EPiServer.Core;
using EPiServer.Core.PropertySettings;
using EPiServer.Editor.TinyMCE;
using EPiServer.Security;
using EPiServer.ServiceLocation;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace AlloyDemoKit.Business
[ServiceConfiguration(ServiceType = typeof(PropertySettings))]
public class DefaultTinyMCESettings : PropertySettings<TinyMCESettings>
public DefaultTinyMCESettings()
IsDefault = true;
DisplayName = "Standard";
Description = "Standard profil. Får ej redigeras";
public override TinyMCESettings GetPropertySettings()
IPropertySettingsRepository PropertySettingsRepository = EPiServer.ServiceLocation.ServiceLocator.Current.GetInstance<IPropertySettingsRepository>();
//We need to dupecheck buttons because else we get weird behavior
var addedButtons = new Dictionary<string, string>();
//Load propertysettings
var allWrappers = PropertySettingsRepository.GetGlobals(typeof(TinyMCESettings));
var ordinaryWrapper = allWrappers.FirstOrDefault(x => x.DisplayName.Equals("Ordinary", StringComparison.InvariantCultureIgnoreCase));
var xordinaryWrapper = allWrappers.FirstOrDefault(x => x.DisplayName.Equals("ExtraOrdinary", StringComparison.InvariantCultureIgnoreCase));
//Combine settings
var settings = new TinyMCESettings();
//Copy from ordinary
if (ordinaryWrapper != null)
var ordinaryWrapperTinySettings = ordinaryWrapper.PropertySettings as TinyMCESettings;
CreateToolbars(settings, ordinaryWrapperTinySettings, addedButtons);
//Add xtraordinary settings for specific roles
if (PrincipalInfo.CurrentPrincipal.IsInRole("administrators") && xordinaryWrapper != null)
var xordinaryWrapperTinySettings = xordinaryWrapper.PropertySettings as TinyMCESettings;
CreateToolbars(settings, xordinaryWrapperTinySettings, addedButtons);
// Add the default non-visual plugins that replaces built in functionality with EPiServer specifics.
settings.Height = 200;
settings.Width = 600;
return settings;
public override System.Guid ID
get { return new System.Guid("a6fe936f-190d-45e2-b83c-ccc0501a7312"); }
private void CreateToolbars(TinyMCESettings toSetting, TinyMCESettings fromSetting, Dictionary<string, string> addedButtons)
int duplicateKeyFound = 0;
int buttonsInRow = 0;
foreach (var row in fromSetting.ToolbarRows)
var toolBarXtraOrdinary = new ToolbarRow();
duplicateKeyFound = 0;
buttonsInRow = row.Buttons.Count;
foreach (var button in row.Buttons)
if (!addedButtons.ContainsKey(button))
addedButtons.Add(button, button);
if (buttonsInRow != duplicateKeyFound)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.