4

I have created a custom pipeline in a Foundation level Helix module. At the moment it has a single processor which can have multiple parameter configuration elements.

In my project layer, I want to patch this configuration to supply a new set of parameters for the existing pipeline. For some reason only the last parameter is getting patched.

Foundation module config:

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <getCustomTaggingPageData>
        <processor type="Acme.Foundation.Tagging.Pipelines.GetUserProfileData, Acme.Foundation.Tagging">
          <variablesMapping hint="raw:AddMapping">
          </variablesMapping>
        </processor>
      </getCustomTaggingPageData>
    <getCustomTaggingEventData>
  </getCustomTaggingEventData>
</pipelines>

Project module config:

<configuration
  xmlns:patch="http://www.sitecore.net/xmlconfig/" 
  xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <settings>
      <pipelines>
        <getCustomTaggingPageData>
          <processor type="Acme.Foundation.Tagging.Pipelines.GetUserProfileData, Acme.Foundation.Tagging">
            <variablesMapping hint="raw:AddMapping">
              <mapping variableName="[ui:LoggedStatus]" profileProperty="Core:LoggedStatus" />
              <mapping variableName="[ui:User]" profileProperty="Core:User" />
              <mapping variableName="[ui:Email]" profileProperty="Core:EmailId" />
              <mapping variableName="[ui:Gender]" profileProperty="{0AE264FA-8D8F-48BC-8AC3-18B7F54F0DB9}" conditionalValue="mr?m:f" />
              <mapping variableName="[ui:PostalCode]" profileProperty="{D6BA91E2-F7E4-45CC-8FBB-25C2193536AE}" />
              <mapping variableName="[ui:City]" profileProperty="{05665E10-F5E6-4CD3-8159-B682D7972936}" />
              <mapping variableName="[ui:Birthday]" profileProperty="{A465D2A8-3866-4BCC-8352-A106F8C58A92}" dataType="System.DateTime" formatString="yyyy" />
            </variablesMapping>
          </processor>
        </getCustomTaggingPageData>
      </pipelines>
    </sitecore>
</configuration>

Output from ShowConfig.aspx

<getCustomTaggingPageData patch:source="Foundation.Tagging.config">
  <processor type="Acme.Foundation.Tagging.Pipelines.GetUserProfileData, Acme.Foundation.Tagging" patch:source="Sitecore.Project.Overrides.config">
    <variablesMapping hint="raw:AddMapping" patch:source="Sitecore.Project.Overrides.config">
      <mapping variableName="[ui:Birthday]" profileProperty="{A465D2A8-3866-4BCC-8352-A106F8C58A92}" patch:source="Sitecore.Project.Overrides.config" conditionalValue="mr?m:f" dataType="System.DateTime" formatString="yyyy"/>
    </variablesMapping>
  </processor>
</getCustomTaggingPageData>
5

The issue is the extra <settings> node in your project module config, at the moment you're not patching anything but inserting a new entry within the <settings> node (and it's probably not where you're looking in showconfig.aspx)

<configuration
  xmlns:patch="http://www.sitecore.net/xmlconfig/" 
  xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <pipelines>
      <getCustomTaggingPageData>
        <processor type="Acme.Foundation.Tagging.Pipelines.GetUserProfileData, Acme.Foundation.Tagging">
          <variablesMapping hint="raw:AddMapping">
            <mapping variableName="[ui:LoggedStatus]" profileProperty="Core:LoggedStatus" />
            <mapping variableName="[ui:User]" profileProperty="Core:User" />
            <mapping variableName="[ui:Email]" profileProperty="Core:EmailId" />
            <mapping variableName="[ui:Gender]" profileProperty="{0AE264FA-8D8F-48BC-8AC3-18B7F54F0DB9}" conditionalValue="mr?m:f" />
            <mapping variableName="[ui:PostalCode]" profileProperty="{D6BA91E2-F7E4-45CC-8FBB-25C2193536AE}" />
            <mapping variableName="[ui:City]" profileProperty="{05665E10-F5E6-4CD3-8159-B682D7972936}" />
            <mapping variableName="[ui:Birthday]" profileProperty="{A465D2A8-3866-4BCC-8352-A106F8C58A92}" dataType="System.DateTime" formatString="yyyy" />
          </variablesMapping>
        </processor>
      </getCustomTaggingPageData>
    </pipelines>
  </sitecore>
</configuration>

I would also suggest that you add additional attributes to your processor to make your patching simpler between foundation and project layer, which I previously blogged about.

Foundation Module Config

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <pipelines>
      <getCustomTaggingPageData>
        <processor name="GetUserProfileData" type="Acme.Foundation.Tagging.Pipelines.GetUserProfileData, Acme.Foundation.Tagging">
          <variablesMapping hint="raw:AddMapping">
          </variablesMapping>
        </processor>
      </getCustomTaggingPageData>
    <getCustomTaggingEventData>
  </getCustomTaggingEventData>
</pipelines>

Project Module Config

<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <pipelines>
      <getCustomTaggingPageData>
        <processor name="GetUserProfileData">
          <variablesMapping>
            <mapping variableName="[ui:LoggedStatus]" profileProperty="Core:LoggedStatus" />
            ...
          </variablesMapping>
        </processor>
      </getCustomTaggingPageData>
    </pipelines>
  </sitecore>
</configuration>

Note that we do not specify the type on our project module config. This will mean that if you change the type signature you no longer need to change it in 2 places and the configuration remains only in the foundation layer.

  • Good catch - I completely missed that <settings> node. This is the right answer - removing mine – Richard Seal Sep 21 '17 at 20:11
  • Hi jammykam thanks for the answer! I found I had to also use @Richard Seal's technique of using the hint as well to make this work. – Matthew Dresser Sep 21 '17 at 23:19
4

This is down to how Sitecore patches child items. The same thing happens if you try to patch the publish:end configuration to add your site in. The problem is that because each of your mapping entries are effectively the same and don't contain any patching hints, each row patches the one above.

To solve that you can add a hint attribute to each row like this:

<configuration
  xmlns:patch="http://www.sitecore.net/xmlconfig/" 
  xmlns:set="http://www.sitecore.net/xmlconfig/set/">
  <sitecore>
    <settings>
      <pipelines>
        <getCustomTaggingPageData>
          <processor type="Acme.Foundation.Tagging.Pipelines.GetUserProfileData, Acme.Foundation.Tagging">
            <variablesMapping hint="raw:AddMapping">
              <mapping hint="LoggedStatus" variableName="[ui:LoggedStatus]" profileProperty="Core:LoggedStatus" />
              <mapping hint="User" variableName="[ui:User]" profileProperty="Core:User" />
              <mapping hint="Email" variableName="[ui:Email]" profileProperty="Core:EmailId" />
              <mapping hint="Gender" variableName="[ui:Gender]" profileProperty="{0AE264FA-8D8F-48BC-8AC3-18B7F54F0DB9}" conditionalValue="mr?m:f" />
              <mapping hint="PostalCode" variableName="[ui:PostalCode]" profileProperty="{D6BA91E2-F7E4-45CC-8FBB-25C2193536AE}" />
              <mapping hint="City" variableName="[ui:City]" profileProperty="{05665E10-F5E6-4CD3-8159-B682D7972936}" />
              <mapping hint="Birthday" variableName="[ui:Birthday]" profileProperty="{A465D2A8-3866-4BCC-8352-A106F8C58A92}" dataType="System.DateTime" formatString="yyyy" />
            </variablesMapping>
          </processor>
        </getCustomTaggingPageData>
      </pipelines>
    </sitecore>
</configuration>

When patching, Sitecore will see the hint attribute and this time add each line as a new line.

This is the same way that we would patch in the sites node on the publish:end handler:

<event name="publish:end">
    <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache">
        <sites hint="list">
            <site hint="mysitename1">mysitename1</site>
            <site hint="mysitename2">mysitename2</site>
        </sites>
    </handler>
</event>

Without the hint there, these would just replace the website entry from the default config, and mysitename2 would override mysitename1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.