<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sitecore Xperiences &#187; Richtext Editor</title>
	<atom:link href="https://blog.peplau.com.br/category/richtext-editor/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.peplau.com.br</link>
	<description>The things I&#039;ve seen as a Sitecore Professional</description>
	<lastBuildDate>Sun, 09 Mar 2025 21:54:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.41</generator>
	<item>
		<title>Site-specific RichText Editor Profiles - custom Source in native RichText fields</title>
		<link>https://blog.peplau.com.br/site-specific-richtext-editor-profiles-custom-source-in-native-richtext-fields/</link>
		<comments>https://blog.peplau.com.br/site-specific-richtext-editor-profiles-custom-source-in-native-richtext-fields/#comments</comments>
		<pubDate>Sat, 06 Jan 2018 13:42:31 +0000</pubDate>
		<dc:creator><![CDATA[Rodrigo Peplau]]></dc:creator>
				<category><![CDATA[Content Edition Experience]]></category>
		<category><![CDATA[Experience Editor]]></category>
		<category><![CDATA[Richtext Editor]]></category>

		<guid isPermaLink="false">http://blog.peplau.com.br/?p=665</guid>
		<description><![CDATA[<div class="lr_horizontal_share" data-share-url="https://blog.peplau.com.br/site-specific-richtext-editor-profiles-custom-source-in-native-richtext-fields/"></div>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. Hardcoded??? But what if we could make this dynamic and site-specific? That way, the same template could present different Editor Profiles [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>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.</p>
<p><a href="http://blog.peplau.com.br/wp-content/uploads/Rich-Text-Source-property.png"><img class="alignnone size-full wp-image-666" src="http://blog.peplau.com.br/wp-content/uploads/Rich-Text-Source-property.png" alt="Rich Text Source property" width="1174" height="176" /></a></p>
<h2>Hardcoded???</h2>
<p>But what if we could make this dynamic and site-specific? That way, the same template could present different Editor Profiles for different websites.</p>
<p>Something like this:</p>
<p><a href="http://blog.peplau.com.br/wp-content/uploads/Rich-Text-Site-specific-Source-property.png"><img class="alignnone size-full wp-image-667" src="http://blog.peplau.com.br/wp-content/uploads/Rich-Text-Site-specific-Source-property.png" alt="Rich Text Site-specific Source property" width="703" height="172" /></a></p>
<p>Then at each of your websites you can have your own Source definition item:</p>
<p><a href="http://blog.peplau.com.br/wp-content/uploads/Site-Specific-RichText-Editor-Source.png"><img class="alignnone size-full wp-image-668" src="http://blog.peplau.com.br/wp-content/uploads/Site-Specific-RichText-Editor-Source.png" alt="Site-Specific RichText Editor Source" width="775" height="271" /></a></p>
<p>Cool?</p>
<h2>Site-specific field Sources</h2>
<p>If you ever happen to play with Habitat you might have noticed it has a <a href="https://github.com/Sitecore/Habitat/tree/master/src/Foundation/Multisite/code" target="_blank">Multisite Module</a>, that implements something similar for Component&#8217;s Datasources. My solution is based on that, working perfectly with Droplists and other listing fields.</p>
<h2>Not so fast&#8230;</h2>
<p>But unfortunately, it doesn&#8217;t work with the RichText field since it is attached to the &#8220;&lt;getLookupSourceItems&gt;&#8221; pipeline. The RichText field has a different implementation which does not trigger this pipeline.</p>
<h2>Custom Source for Rich Text fields!</h2>
<p>So how can this be customized? After a long web research and decompiling Sitecore DLLs, here is what I came out.</p>
<p>If you take a look at the Field item definition under <em>core:/sitecore/system/Field types/Simple Types/Rich Text</em> you will notice it has the following content at the Control field:</p>
<p><a href="http://blog.peplau.com.br/wp-content/uploads/Rich-Text-definition-item.png"><img class="alignnone size-full wp-image-669" src="http://blog.peplau.com.br/wp-content/uploads/Rich-Text-definition-item.png" alt="Rich Text definition item" width="408" height="91" /></a></p>
<p>I found out that this is similar to how a Command is registered, however no such a Command called &#8220;content:RichText&#8221; exists anywhere at my Sitecore configs. This is actually registered by the following config entry:</p>
<pre class="line"><span class="html-tag">&lt;controlSources&gt;
</span>    &lt;source<span class="html-attribute"> <span class="html-attribute-name">assembly</span>="<span class="html-attribute-value">Sitecore.Kernel</span>"</span><span class="html-attribute"> <span class="html-attribute-name">namespace</span>="<span class="html-attribute-value">Sitecore.Shell.Applications.ContentEditor</span>"</span><span class="html-attribute"> <span class="html-attribute-name">prefix</span>="<span class="html-attribute-value">content</span>"</span><span class="html-attribute"> <span class="html-attribute-name">mode</span>="<span class="html-attribute-value">on</span>"</span>/&gt;</pre>
<p class="collapsible-content">The secret here is the <em>prefix=&#8221;content&#8221;</em> which is used as the basis to register the whole namespace, taking classes dynamically by its name (&#8220;RichText&#8221; in this case).</p>
<h3 class="collapsible-content">Step 1 &#8211; Extend native class</h3>
<p class="collapsible-content">Create your class that extends the Rich Text field &#8211; we will inherit from the original &#8220;<em>Sitecore.Shell.Applications.ContentEditor.RichText</em>&#8221; and only overwrite the Source property. Notice that I am re-using the same code used at my &lt;getLookupSourceItems&gt; to apply the same logic to the Rich Text field.</p>
<pre>using Sitecore.Diagnostics;
using Sitecore.Pipelines.GetLookupSourceItems;
using Website.Core.Multisite.Pipelines;
namespace Website.Core.Fields
{
   public class RichText : Sitecore.Shell.Applications.ContentEditor.RichText
   {
     /// &lt;summary&gt;Gets or sets the source.&lt;/summary&gt;
     /// &lt;value&gt;The source.&lt;/value&gt;
     public new string Source
     {
       get { return GetViewStateString(nameof(Source)); }
       set
       {
         Assert.ArgumentNotNull(value, nameof(value));
<strong>         // Reuse the same Pipeline implementation here as at my &lt;getLookupSourceItems&gt; pipeline
</strong><strong>         var processor = new LookupItemsFromField();
</strong><strong>         var args = new GetLookupSourceItemsArgs()
</strong><strong>         {
</strong><strong>           Source = value,
</strong><strong>           Item = Sitecore.Context.ContentDatabase.GetItem(ItemID)
</strong><strong>         };
</strong><strong>         processor.Process(args);
</strong><strong>         value = args.Source;
</strong>         SetViewStateString(nameof(Source), value);
       }
    }
  }
}</pre>
<h3 class="collapsible-content">Step 2 &#8211; Patch Sitecore to use our custom class</h3>
<p class="collapsible-content">Now we need to patch Sitecore. Our custom class needs to be registered BEFORE the native one so it can assume its place.</p>
<pre>&lt;?xml version="1.0"?&gt;
  &lt;configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"&gt;
    &lt;sitecore&gt;
      &lt;controlSources&gt;
        &lt;source patch:before="source[@namespace='Sitecore.Shell.Applications.ContentEditor']" mode="on" namespace="Website.Core.Fields" assembly="Website.Core" prefix="content"/&gt;
      &lt;/controlSources&gt;
    &lt;/sitecore&gt;
&lt;/configuration&gt;</pre>
<p class="collapsible-content">Now that you can intercept the native RichText implementation, you can implement your own logic for Source resolving!</p>
<p class="collapsible-content">You know a better way of doing this? Please let me know!</p>
]]></content:encoded>
			<wfw:commentRss>https://blog.peplau.com.br/site-specific-richtext-editor-profiles-custom-source-in-native-richtext-fields/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
