World is now on Opti ID! Learn more

Linus Ekström
Dec 4, 2013
  7133
(0 votes)

Custom root for category selection and EditorDescriptorBehavior

In this blog post I’ll describe how to set a custom root for a category property. The code for this is pretty simple:

[EditorDescriptorRegistration(TargetType = typeof(CategoryList), UIHint = "customcategoryroot", EditorDescriptorBehavior = EditorDescriptorBehavior.ExtendBase)]
public class CategoryListEditorDescriptor : EditorDescriptor
{
    public override void ModifyMetadata(EPiServer.Shell.ObjectEditing.ExtendedMetadata metadata, System.Collections.Generic.IEnumerable attributes)
    {
        metadata.EditorConfiguration["root"] = Category.GetRoot().Categories[0].ID;
    }
}

The actual logic is pretty simple, set the “root” property to the widget that is responsible for editing (this only works in 7.5 due to some changes in the client widget to support this). In this sample the settings will only affect any CategoryLists tagged with the UIHint “customcategoryroot” but removing this will make the descriptor affect all category-properties, including the built in one.

EditorDescriptorBehavior

So how does the editing system know how to edit the property since we are not defining an editor widget? The answer to this is that we have defined the new attribute property EditorDescriptorBehavior. In this case we are setting this property to EditorDescriptorBehavior.ExtendBase which means that we want to run the default editor descriptors for the type (in this case the default descriptor for CategoryList without any UIHint) first and then this editor descriptor. This makes is possible to extend the behavior without taking having to know about the class responsible for the default implementation. There are a few posibilities to set for this property which the SDK explains like this:

/// 
/// Adds this descriptor to the list of descriptors for the given type and ui hint combination.
/// 
Default = 0,
/// 
/// Adds this descriptor to the list of descriptors for the given type and ui hint combination and
/// makes sure that the descriptors registered without a ui hint for the type are called before this descriptor.
/// 
/// This is only valid in combination with a ui hint.
ExtendBase = 1,
/// 
/// Removes any existing descriptors for the type/ui hint combination and then adds this descriptor.
/// 
OverrideDefault = 2,
/// 
/// Adds this descriptor last in the list of descriptors for the given type and ui hint combination.
/// 
/// If several descriptors are defined this way the order of execution is undefined.PlaceLast = 3

There is one known limitation that you might to be aware of: You cannot extend an editor descriptor that already has a UIHint defined. So if you want to extend ContentReferences hinted with for example a “Page”, you cannot override this behavior direcly (though this can be simply archieved which will be content for another blog post).

Dec 04, 2013

Comments

Please login to comment.
Latest blogs
Make Global Assets Site- and Language-Aware at Indexing Time

I had a support case the other day with a question around search on global assets on a multisite. This is the result of that investigation. This co...

dada | Jun 26, 2025

The remote server returned an error: (400) Bad Request – when configuring Azure Storage for an older Optimizely CMS site

How to fix a strange issue that occurred when I moved editor-uploaded files for some old Optimizely CMS 11 solutions to Azure Storage.

Tomas Hensrud Gulla | Jun 26, 2025 |

Enable Opal AI for your Optimizely products

Learn how to enable Opal AI, and meet your infinite workforce.

Tomas Hensrud Gulla | Jun 25, 2025 |

Deploying to Optimizely Frontend Hosting: A Practical Guide

Optimizely Frontend Hosting is a cloud-based solution for deploying headless frontend applications - currently supporting only Next.js projects. It...

Szymon Uryga | Jun 25, 2025

World on Opti ID

We're excited to announce that world.optimizely.com is now integrated with Opti ID! What does this mean for you? New Users:  You can now log in wit...

Patrick Lam | Jun 22, 2025

Avoid Scandinavian Letters in File Names in Optimizely CMS

Discover how Scandinavian letters in file names can break media in Optimizely CMS—and learn a simple code fix to automatically sanitize uploads for...

Henning Sjørbotten | Jun 19, 2025 |