1

Sitecore 8.2u4

We are losing rendering parameter values during the cloning process of certain fields.

Steps to reproduce:

  1. Create a page item (item with Presentation Details)
  2. Add a Rendering to the page with a custom Rendering Parameters template assigned
  3. Be sure to be using a custom field type in the Rendering Parameters template
  4. Update the Rendering Parameters on the rendering (likely in Final Layout)
  5. Clone the page item elsewhere

After performing the steps above, the cloned items do not have the same rendering parameters set in their Presentation Details.

1

Sitecore 8

The issue is caused by:

  • incorrectly coded custom fields on the Rendering Parameters template.
  • the setting ItemCloning.RelinkClonedSubtree set to true

During the cloning process, if ItemCloning.RelinkClonedSubtree is true, Sitecore runs ReferenceReplacementJob.Start. This method is primarily intended to update the presentation details of the clone to point to newly-cloned relative datasources of the clone. Essentially,

if the source item links to an item (like a child datasource) and the linked item was cloned as part of the cloning process, it relinks the linked item to the new clone parent via updating the Presentation Details.

As part of this process, however, it parses the rendering parameters and attempts to cast each field to the type Sitecore.Data.Fields.CustomField. If it fails, the Rendering Parameter value is not added to the clone.

The solution, therefore, is to ensure any custom Content Editor fields inherit from the CustomField class and can thus be cast properly.

public class MyCustomTextField : CustomField
{
    // My implementation
}

Interestingly, many guides do not stress the importance of inheriting this class when building a custom field- even Sitecore's own documentation does not mention this.

On top of that, the out-of-the-box Integer field does not inherit the CustomField class and is susceptible to the same behavior.

Sitecore 9

This issue is not present in Sitecore 9. The ReferenceReplacementJob piece was replaced by a pipeline and was likely refactored to account for this.

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.