Monday, September 30, 2019

Override xaml.xml files in the ~/sitecore/shell/override folder

Occasionally you'll have the desire to add your own custom functionality to dialogs in the Content Editor.  Many of these dialogs can be found under the ~/sitecore/shell/ folder.

Sitecore already comes pre-configured to look in the ~/sitecore/shell/override to find override XmlControls under the node.  That is baked into the Sitecore.config file.

<controlSources>
  <source mode="on" namespace="Sitecore.Web.UI.XmlControls" folder="/sitecore/shell/override" deep="true"/>

This allows you to drop into that folder your customized .xml dialog file that contains your own layout and custom CodeBeside.  The Content Editor will load that one instead of the Sitecore coded one.

However some of the controls under the ~/sitecore/shell/ folder are built with a different technology.

(To read more about the two different control types, Mark Stiles has done an amazing job at documenting them: https://markstiles.net/blog/2014/1/5/sheer-ui-1-a-tale-of-two-systems/)

The extension of these controls is xaml.xml.  Sitecore defines where it finds these controls in the xamlSharp.config file.  Oddly enough, this one doesn't include the  ~/sitecore/shell/override folder.

It is simple to create your own override config for this in Sitecore.

1. Create a new file called xamlSharpOverride.config

2. It should contain the following:
<configuration>
  <sitecore>
    <xamlsharp>
      <sources>
        <source type="Sitecore.Web.UI.XamlSharp.Xaml.XamlFileControlSource,Sitecore.Kernel" patch:before="*">
          <watchers hint="list:AddWatcher">
            <watcher type="Sitecore.Web.UI.XamlSharp.Xaml.XamlFileWatcher,Sitecore.Kernel">
              <folder>/sitecore/shell/override</folder>
              <filter>*.xaml.xml</filter>
              <codefilter>*.xaml.xml.cs</codefilter>
              <includesubdirectories>true</includesubdirectories>
            </watcher>
          </watchers>
        </source>
      </sources>
    </xamlsharp>
  </sitecore>
</configuration>

This config will insert that source folder at the top of the xamlSharp sources list.  Any .xaml.xml file you customize can now be placed into the ~/sitecore/shell/override folder.

1 comment: