A complete example of how to manage global TinyMCE settings for your XHTML-string properties.

I started out from Joel's post on Page Type Builder 2 Preview 1 and chose to keep handling my editor settings as global ones (see heading Managing global settings).

My project needed ImageVault buttons and a quite different order of all toolbar buttons than the default. To find the button and plugin names i just hit View Frame Source in the Edit Mode frame of a similiar site in my Firefox and analyzed the calls to tinyMCE.init().

The classes

The settings for the web site's MainBody properties and similiar (also set as default setting):

namespace Krompaco.Project.Settings
{
    using System.Collections.Generic;
    using System.Linq;
    using EPiServer.Core.PropertySettings;
    using EPiServer.Editor.TinyMCE;
    using PageTypeBuilder;

    public class EditorSettingDefault : IUpdateGlobalPropertySettings
    {
        public string DisplayName
        {
            get { return "Standard Setting (ImageVault)"; }
        }

        public string Description
        {
            get { return string.Empty; }
        }

        public bool? IsDefault
        {
            get { return true; }
        }

        public bool OverWriteExistingSettings
        {
            get { return true; }
        }

        public bool Match(PropertySettingsWrapper propertySettingsWrapper)
        {
            return propertySettingsWrapper.DisplayName.Equals(this.DisplayName);
        }

        public void UpdateSettings(TinyMCESettings settings)
        {
            settings.ToolbarRows.Clear();

            var toolbarRow1 = new ToolbarRow(new List { "bold", "italic", "separator", "numlist",
              "bullist", "cite", "separator", "undo", "redo", "separator", "linktool", "unlink",
              "anchor", "separator", "imagevault", "epidynamiccontent", "epipersonalizedcontent",
              "separator", "pastetext", "cleanup", "removeformat", "separator", "search", "replace",
              "separator", "code", "fullscreen" });
            var toolbarRow2 = new ToolbarRow(new List { "formatselect", "styleselect", "table",
              "row_props", "cell_props", "separator", "row_before", "row_after", "delete_row",
              "separator", "col_before", "col_after", "delete_col", "separator", "split_cells",
              "merge_cell" });

            settings.ToolbarRows.Add(toolbarRow1);
            settings.ToolbarRows.Add(toolbarRow2);

            settings.ContentCss = "/css/editor.css";
            settings.Width = 600;
            settings.Height = 400;
            
            // Putting the javascript plugin name here equals checked box in Admin Mode
            settings.NonVisualPlugins = new[] { "advimage", "krompacooptimizededitor", "contextmenu" };
        }

        public int GetSettingsHashCode(TinyMCESettings settings)
        {
            var flattened = settings.ToolbarRows.SelectMany(row => row.Buttons);
            return string.Concat(flattened, settings.NonVisualPlugins, settings.ContentCss).GetHashCode()
              + settings.Width + settings.Height;
        }
    }
}

The settings for the web site's MainIntro properties and similiar (fewer buttons and lower height):

namespace Krompaco.Project.Settings
{
    using System.Collections.Generic;
    using System.Linq;
    using EPiServer.Core.PropertySettings;
    using EPiServer.Editor.TinyMCE;
    using PageTypeBuilder;

    public class EditorSettingIntro : IUpdateGlobalPropertySettings
    {
        public string DisplayName
        {
            get { return "Intro Setting (ImageVault)"; }
        }

        public string Description
        {
            get { return string.Empty; }
        }

        public bool? IsDefault
        {
            get { return false; }
        }

        public bool OverWriteExistingSettings
        {
            get { return true; }
        }

        public bool Match(PropertySettingsWrapper propertySettingsWrapper)
        {
            return propertySettingsWrapper.DisplayName.Equals(this.DisplayName);
        }

        public void UpdateSettings(TinyMCESettings settings)
        {
            settings.ToolbarRows.Clear();

            var toolbarRow1 = new ToolbarRow(new List { "bold", "italic", "separator", "undo", "redo",
              "separator", "linktool", "unlink", "anchor", "separator", "imagevault", "epidynamiccontent",
              "epipersonalizedcontent", "separator", "pastetext", "cleanup", "removeformat", "separator",
              "search", "replace", "separator", "code", "fullscreen" });
            var toolbarRow2 = new ToolbarRow(new List { "formatselect", "styleselect" });

            settings.ToolbarRows.Add(toolbarRow1);
            settings.ToolbarRows.Add(toolbarRow2);

            settings.ContentCss = "/css/editor.css";
            settings.Width = 600;
            settings.Height = 210;

            // Putting the javascript plugin name here equals checked box in Admin Mode
            settings.NonVisualPlugins = new[] { "advimage", "krompacooptimizededitor", "contextmenu" };
        }

        public int GetSettingsHashCode(TinyMCESettings settings)
        {
            var flattened = settings.ToolbarRows.SelectMany(row => row.Buttons);
            return string.Concat(flattened, settings.NonVisualPlugins, settings.ContentCss).GetHashCode()
              + settings.Width + settings.Height;
        }
    }
}

Usage

Then just put a UseGlobalSettings attribute on your property like this:

[PageTypeProperty(EditCaption = "Introduction Text", Type = typeof(PropertyXhtmlString),
SortOrder = 1100, UniqueValuePerLanguage = true, Searchable = true)]
[UseGlobalSettings(typeof(EditorSettingIntro))]
public virtual string MainIntro { get; set; }

Tested using EPiServer CMS 6 R2 and Page Type Builder 2.0.

Added Wednesday 5 September 2012 09:17 — Tags for this page: Episerver, TinyMCE

Comments

  1. Jon Espen Kvisler Friday 7 September 2012 10:08

    Great work! I created a similiar plugin some time ago with more simple editor, hiding the advanced stuff trough a "kitchen sink" button: http://jonespen.posterous.com/sspcustomeditor

    Nuget: http://nuget.episerver.com/en/OtherPages/Package/?packageId=SSP.CustomEditor

  2. Andreas Gomm Wednesday 26 June 2013 10:16

    Great post! I was looking for a way to do this with C# instead of Admin Mode.

  3. Author Comment Wednesday 26 June 2013 10:20

    Thanks!

Add Your Comment