Last active
October 9, 2016 14:33
-
-
Save PNergard/87b0648d8336aa3af53e71f51ac21e1e to your computer and use it in GitHub Desktop.
Different editor tool buttons for normal editors and administrators. Read more over at my blog: http://world.episerver.com/blogs/Per-Nergard/Dates/2016/10/special-editor-toolbuttons-for-administrators/
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.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.NonVisualPlugins.Add("advimage"); | |
settings.NonVisualPlugins.Add("epifilebrowser"); | |
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); | |
toolBarXtraOrdinary.Buttons.Add(button); | |
} | |
else | |
duplicateKeyFound++; | |
} | |
if (buttonsInRow != duplicateKeyFound) | |
toSetting.ToolbarRows.Add(toolBarXtraOrdinary); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment