Magnus Baneryd
May 22, 2018
  2555
(8 votes)

TinyMCE Configuration API news

We recently added some new exciting features to the TinyMCE configuration API based on feedback from the the forums.

Inherit settings from an ancestor

We heard that you would like to be able to configure settings on a base class and then override them further down in the hierarchy, so you do not have to duplicate the code for setting the setting on all leaf classes. E.g.

Before

abstract class ProductBase
{
    public virtual XHtml ProductDescription {get;set;}
}

class ProductPage : ProductBase
{
}

class ShoeProductPage : ProductPage
{
}

class ShirtProductPage : ProductPage
{
}

class BlueShirtProductPage : ShirtProductPage
{
}

class VerySpecialProductPage : ProductPage
{
}

class AndEvenMoreSpecialProductPage : VerySpecialProductPage
{
}


// Init
context.Services.Configure<TinyMceConfiguration>(config =>
{
    var baseSettings = config.Default().Clone();
    baseSettings
        .AddPlugin("product-selector")
        .AppendToolbar("product-selector");

    config.For<ProductPage>(t=>t.ProductDescription, baseSettings);
    config.For<ShoeProductPage>(t=>t.ProductDescription, baseSettings);
    config.For<ShirtProductPage>(t=>t.ProductDescription, baseSettings);
    config.For<BlueShirtProductPage>(t=>t.ProductDescription, baseSettings);
    config.For<VerySpecialProductPage>(t=>t.ProductDescription, baseSettings);
    config.For<AndEvenMoreSpecialProductPage>(t=>t.ProductDescription, baseSettings);
})

After

// Init
context.Services.Configure<TinyMceConfiguration>(config =>
{
     // Enable inheritance of settings
    config.InheritSettingsFromAncestor= true;

    var baseSettings = config.Default().Clone();
    baseSettings
        .AddPlugin("product-selector")
        .AppendToolbar("product-selector");

    config.For<ProductBase>(t=>t.ProductDescription, baseSettings);
})
This new behavior is something that you need to enable, by setting InheritSettingsFromAncestor to true. We could not change the new behavior without doing a breaking change, so we decided to hide it behind the InheritSettingsFromAncestor flag instead.
You can read more about the API in the SDK - (Inherit settings from ancestors)

Setting transformations

The setting transformation features makes it possible for you to add a callback method that will run when we load the settings for a specific content item. And it enables you do modify the setting object before we return it to the client.
 
context.Services.Configure<TinyMceConfiguration>(config =>
{
    ...
    
    // If you are writing a plugin we recommend you to add the transformation when you add the plugin.
    config.Default()
        .AddExternalPlugin("custom-plugin","/path/to/my/plugin.js", (settings, content, propertyName) => {
            settings["custom-plugin-setting"] = "plugin value";
        });
 
    config.Default()
        .AddSettingsTransform("custom-settings", (settings, content propertyName) => {
            settings["custom-plugin-setting"] = "I have modified the plugins settings value";
        });
 
    ...
}
You can read more about the API in the SDK - Settings transformations
 

We hope these changes makes it easier for you to configure TinyMCE, and if you have any more feedback on the API, please let us know.

May 22, 2018

Comments

Peter Emilsson
Peter Emilsson May 23, 2018 11:11 AM

Setting transformations look very useful!

How do I configure TinyMce for a property on a model/class in PropertyList?

Aria Zanganeh
Aria Zanganeh May 23, 2018 01:45 PM

this is really helpful :) as I'm pretty sure we will make many configs we will end up the big mess .. if there is any visualization tool that describes what config is used where would be great .. 

Please login to comment.
Latest blogs
Opti ID overview

Opti ID allows you to log in once and switch between Optimizely products using Okta, Entra ID, or a local account. You can also manage all your use...

K Khan | Jul 26, 2024

Getting Started with Optimizely SaaS using Next.js Starter App - Extend a component - Part 3

This is the final part of our Optimizely SaaS CMS proof-of-concept (POC) blog series. In this post, we'll dive into extending a component within th...

Raghavendra Murthy | Jul 23, 2024 | Syndicated blog

Optimizely Graph – Faceting with Geta Categories

Overview As Optimizely Graph (and Content Cloud SaaS) makes its global debut, it is known that there are going to be some bugs and quirks. One of t...

Eric Markson | Jul 22, 2024 | Syndicated blog

Integration Bynder (DAM) with Optimizely

Bynder is a comprehensive digital asset management (DAM) platform that enables businesses to efficiently manage, store, organize, and share their...

Sanjay Kumar | Jul 22, 2024

Frontend Hosting for SaaS CMS Solutions

Introduction Now that CMS SaaS Core has gone into general availability, it is a good time to start discussing where to host the head. SaaS Core is...

Minesh Shah (Netcel) | Jul 20, 2024

Optimizely London Dev Meetup 11th July 2024

On 11th July 2024 in London Niteco and Netcel along with Optimizely ran the London Developer meetup. There was an great agenda of talks that we put...

Scott Reed | Jul 19, 2024