How to inherit TinyMCE config from base content type in Episerver

Karl Solgård

A tiny tip for all of you that have set up the newest TinyMCE package for Episerver. With Episerver version 11, TinyMCE got updated to the newest version and got its own nuget package.

The new configuration of TinyMCE in Episerver 11 can get a bit messy. Especially if you have many content types with the same properties. You might've also noticed that the configuration doesn't work on base content types out of the box. You have to set config.InheritSettingsFromAncestor = true; to activate inheritance on these properties. Here defined in the documentation.

This example will show how that property will apply the same configuration for every class that inherits BaseArticlePage.

[ModuleDependency(typeof(TinyMceInitialization))]
public class ExtendedTinyMceInitialization : IConfigurableModule
{
    public void Initialize(InitializationEngine context)
    {
    }

    public void Uninitialize(InitializationEngine context)
    {
    }

    public void ConfigureContainer(ServiceConfigurationContext context)
    {
        context.Services.Configure<TinyMceConfiguration>(config =>
        {
            config.InheritSettingsFromAncestor = true;
            config.For<BaseArticlePage>(a => a.TextContent)
                .AddPlugin("image", "link")
                .Toolbar(
                    "epi-link unlink image epi-image-editor | cut copy paste | " +
                    "undo redo | bold italic underline" +
                    "code | searchreplace fullscreen"
                );
        });
    }
}

I personally think that it's strange that the InheritSettingsFromAncestor isn't set to true by default.