• About this blog
  • About me
  • Contact
Sitecore XperiencesThe things I've seen as a Sitecore Professional
  • About this blog
  • About me
  • Contact
Menu
  • About this blog
  • About me
  • Contact
  • Site-specific RichText Editor Profiles - custom Source in native RichText fields

    January 6, 2018 Rodrigo Peplau 0

    Site-specific RichText Editor Profiles - custom Source in native RichText fields

    Everybody knows how to select different Editor Profiles using the Source property in a Rich Text field. Out of the box, you can only pass a hardcoded path to the Editor Profile, making the template totally linked to one and only one Profile.

    Rich Text Source property

    Hardcoded???

    But what if we could make this dynamic and site-specific? That way, the same template could present different Editor Profiles for different websites.

    Something like this:

    Rich Text Site-specific Source property

    Then at each of your websites you can have your own Source definition item:

    Site-Specific RichText Editor Source

    Cool?

    Site-specific field Sources

    If you ever happen to play with Habitat you might have noticed it has a Multisite Module, that implements something similar for Component’s Datasources. My solution is based on that, working perfectly with Droplists and other listing fields.

    Not so fast…

    But unfortunately, it doesn’t work with the RichText field since it is attached to the “<getLookupSourceItems>” pipeline. The RichText field has a different implementation which does not trigger this pipeline.

    Custom Source for Rich Text fields!

    So how can this be customized? After a long web research and decompiling Sitecore DLLs, here is what I came out.

    If you take a look at the Field item definition under core:/sitecore/system/Field types/Simple Types/Rich Text you will notice it has the following content at the Control field:

    Rich Text definition item

    I found out that this is similar to how a Command is registered, however no such a Command called “content:RichText” exists anywhere at my Sitecore configs. This is actually registered by the following config entry:

    <controlSources>
        <source assembly="Sitecore.Kernel" namespace="Sitecore.Shell.Applications.ContentEditor" prefix="content" mode="on"/>

    The secret here is the prefix=”content” which is used as the basis to register the whole namespace, taking classes dynamically by its name (“RichText” in this case).

    Step 1 – Extend native class

    Create your class that extends the Rich Text field – we will inherit from the original “Sitecore.Shell.Applications.ContentEditor.RichText” and only overwrite the Source property. Notice that I am re-using the same code used at my <getLookupSourceItems> to apply the same logic to the Rich Text field.

    using Sitecore.Diagnostics;
    using Sitecore.Pipelines.GetLookupSourceItems;
    using Website.Core.Multisite.Pipelines;
    namespace Website.Core.Fields
    {
       public class RichText : Sitecore.Shell.Applications.ContentEditor.RichText
       {
         /// <summary>Gets or sets the source.</summary>
         /// <value>The source.</value>
         public new string Source
         {
           get { return GetViewStateString(nameof(Source)); }
           set
           {
             Assert.ArgumentNotNull(value, nameof(value));
             // Reuse the same Pipeline implementation here as at my <getLookupSourceItems> pipeline
             var processor = new LookupItemsFromField();
             var args = new GetLookupSourceItemsArgs()
             {
               Source = value,
               Item = Sitecore.Context.ContentDatabase.GetItem(ItemID)
             };
             processor.Process(args);
             value = args.Source;
             SetViewStateString(nameof(Source), value);
           }
        }
      }
    }

    Step 2 – Patch Sitecore to use our custom class

    Now we need to patch Sitecore. Our custom class needs to be registered BEFORE the native one so it can assume its place.

    <?xml version="1.0"?>
      <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
        <sitecore>
          <controlSources>
            <source patch:before="source[@namespace='Sitecore.Shell.Applications.ContentEditor']" mode="on" namespace="Website.Core.Fields" assembly="Website.Core" prefix="content"/>
          </controlSources>
        </sitecore>
    </configuration>

    Now that you can intercept the native RichText implementation, you can implement your own logic for Source resolving!

    You know a better way of doing this? Please let me know!

    Categories: Content Edition Experience, Experience Editor, Richtext Editor

    A Helix/TDS Sitecore Solution you can use Still have 'ERROR SCRIPTDOM NEEDED FOR SQL PROVIDER' when installing Sitecore 9?

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Proudly 10x Sitecore MVP!
(2016-2025)

Localization

Recent Posts

  • All Submissions from Sitecore Hackathon 2025!
  • Know your Media Library disk usage with a simple PowerShell script
  • Automated Behavioral Personalization in Sitecore XP with Generative AI
  • MVPinny knows the Sitecore Accelerate for Partners
  • Rodrigo Peplau wins Sitecore Most Valuable Professional award

Recent Comments

  • navan on Meet MVPinny: the AI-Powered Sitecore Assistant
  • Adriana on Content generation with Sitecore Connect and ChatGPT
  • NAVAN on Automatic Sitecore NuGet upgrades with Powershell
  • Hedipo S Menezes on Corey Peplau wrote this - WFFM conflict with Unity DI and a lesson on how Sitecore community is so amazing
  • Rodrigo Peplau on ERROR [Content Testing]: Cannot find PhantomJS executable at ' (...) /data/tools/phantomjs/phantomjs.exe'. Aborting screenshot generation.

Archives

  • March 2025
  • January 2025
  • June 2024
  • April 2024
  • February 2024
  • December 2023
  • November 2023
  • August 2023
  • July 2023
  • January 2023
  • February 2022
  • December 2021
  • November 2021
  • March 2021
  • July 2020
  • February 2020
  • September 2019
  • July 2019
  • April 2019
  • March 2019
  • December 2018
  • February 2018
  • January 2018
  • November 2017
  • September 2017
  • August 2017
  • July 2017
  • March 2017
  • February 2017
  • November 2016
  • September 2016
  • August 2016
  • July 2016
  • April 2016
  • November 2015
  • September 2015
  • July 2015
  • April 2015
  • March 2015
  • February 2015

Categories

  • Actions
  • Active Directory
  • Analytics
  • Architecture
  • Bug fixing
  • CDP/Personalize
  • ChatGPT
  • Content Edition Experience
  • Content Hub
  • Continuous Integration
  • Dev
  • Development
  • Environments
  • Experience Editor
  • Experience Forms
  • Front-end
  • Hackathon
  • Health Check builds
  • Helix
  • How To
  • LDAP
  • MVP
  • MVP Summit
  • MVPinny
  • Phantom JS
  • Powershell
  • QA
  • Richtext Editor
  • Rules
  • Security Provider
  • SIF
  • Sitecore 9
  • Sitecore API
  • Sitecore Community
  • SItecore Connect
  • Sitecore Modules
  • Sitecore Rocks
  • Sitecore Rule Processor
  • Sitecore Symposium
  • SPE
  • SPE-only Alliance
  • SPEAK
  • SUG
  • Support Ticket
  • TDS
  • Team City
  • Uncategorized
  • Upgrades
  • Visual Studio
  • WFFM
  • Workflow
  • XConnect
  • xDB
  • XM Cloud

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Recent Posts

  • All Submissions from Sitecore Hackathon 2025!
  • Know your Media Library disk usage with a simple PowerShell script
  • Automated Behavioral Personalization in Sitecore XP with Generative AI
  • MVPinny knows the Sitecore Accelerate for Partners
  • Rodrigo Peplau wins Sitecore Most Valuable Professional award
  • Error enabling GraphQL IDE with XM Cloud
  • Meet MVPinny: the AI-Powered Sitecore Assistant
  • Content generation with Sitecore Connect and ChatGPT
  • XM Cloud Starter Kit with Content Hub Integration
  • Meet the (Brand new) Advanced Powershell Packaging Features

Tag Cloud

    Architecture Automation Continuous Integration Debugging Development Environments Hackathon How To PhantomJS Powershell Server Roles TDS Team City Team Development for Sitecore XConnect

Pages

  • About this blog
  • About me
  • Contact

Search

Copyright © 2015 Rodrigo Peplau Theme created by PWT. Powered by WordPress.org