EPiServer, Episerver 11

EditorDescriptor and built-in “internal” property names

Moving properties to be displayed in the edit view header is one common task that you might do in your Episerver solution or maybe the most common reference is the “how to hide Episerver standard category“. Also Linus Ekström has blogged about how to hide the category in Episerver 7.5+. But all samples use “magic strings” for the property names. In this post I’ll list those “magic strings” and show you where from those are taken (and next time I don’t need to once again debug these values to remember what is what ;D).

Looking at the ExtendedMetadata

So assuming you already know about the custom EditorDescriptors but in case you are not familiar with those then have a look at the Episerver developer guide and the above linked blog posts.

First I created a simple custom EditorDescriptor (inherit from EditorDescriptor) and used the [EditorDescriptorRegistration(TargetType = typeof(ContentData))] to get it registered for all content types. Then overrode the ModifyMetaData method. Next step was to add a brakepoint in debugger to the start of the method to be able to have a look at the ExtendedMetadata instance passed to the method.

Based on the referenced blog articles (ans past usage) I already knew that the metadata.Properties IEnumerable (but can be cast to the Episerver ExtendedMetadata) contains the properties for the content type and I can use for example “icategorizable_category” to find the default Episerver category property and hide it or move it to another location.

While debugging I noticed there is also property MappedProperties (generic IEnumerable containing PropertyMapping objects) which contained familiar looking property names and these “magic string” property names. For example “icategorizable_category” was “Category” also noticed that on PageData types the “icategorizable_category” was also mapped to a property name “PageCategory”. So obviously here we have the mappings to the EPiServer.DataAbstraction.MetaDataProperties (EPiServer.dll) constants which we are familiar to use in for example in page types when setting default values (override SetDefaultValues) like: this[MetaDataProperties.PageChildOrderRule] = FilterSortOrder.Index; .

Listing the properties for PageData

So next step I did was to loop the Properties and MappedProperties and write the information to a file for inspection. From Properties (generic IEnumerable of type ModelMetadata can be cast to ExtendedMetadata) property we can get the property name, internal name, group name (where the property is shown like on a tab or the header in editor) and order (the order of the property it is displayed in the group) for example. The MappedProperties property only contain information about the mapping To (internal name, like icategorizable_category) and From (friendly name like Category).

While comparing the output I noticed that not all properties in the MappedProperties are actually included in the Properties (mainly the “icontent_contentguid” is not included in the Properties enumerable, using “friendly name” ContentGuid and PageGuid). So I adjusted my logging to iterate the MappedProperties and check that the property name is found from the Properties IEnumerable property and ended up with a listing like this.

PROPERTY NAME         INTERNAL NAME                         GROUP NAME                    ORDER

Name                  icontent_name                         EPiServerCMS_SettingsPanel    -4
PageName              icontent_name                         EPiServerCMS_SettingsPanel    -4
ContentLink           icontent_contentlink                  Information                   -99
PageLink              icontent_contentlink                  Information                   -99
ParentLink            icontent_parentlink                   Information                   -97
PageParentLink        icontent_parentlink                   Information                   -97
ContentGuid           icontent_contentguid                                                
PageGUID              icontent_contentguid                                                
ContentTypeID         icontent_contenttypeid                Information                   -98
PageTypeID            icontent_contenttypeid                Information                   -98
IsDeleted             icontent_isdeleted                    Information                   -93
PageDeleted           icontent_isdeleted                    Information                   -93
Category              icategorizable_category               Information                   -69
PageCategory          icategorizable_category               Information                   -69
Status                iversionable_status                   Advanced                      -95
PageWorkStatus        iversionable_status                   Advanced                      -95
IsPendingPublish      iversionable_ispendingpublish         Advanced                      -96
PagePendingPublish    iversionable_ispendingpublish         Advanced                      -96
StartPublish          iversionable_startpublish             Advanced                      -81
PageStartPublish      iversionable_startpublish             Advanced                      -81
StopPublish           iversionable_stoppublish              Advanced                      -79
PageStopPublish       iversionable_stoppublish              Advanced                      -79
Expire                iversionable_expire                   Information                   0
Shortcut              iversionable_shortcut                 EPiServerCMS_SettingsPanel    -2
Created               ichangetrackable_created              Advanced                      -80
PageCreated           ichangetrackable_created              Advanced                      -80
CreatedBy             ichangetrackable_createdby            Advanced                      -87
PageCreatedBy         ichangetrackable_createdby            Advanced                      -87
Changed               ichangetrackable_changed              Advanced                      -78
PageChanged           ichangetrackable_changed              Advanced                      -78
SetChangedOnPublish   ichangetrackable_setchangedonpublish  Advanced                      -76
PageChangedOnPublish  ichangetrackable_setchangedonpublish  Advanced                      -76
ChangedBy             ichangetrackable_changedby            Advanced                      -86
PageChangedBy         ichangetrackable_changedby            Advanced                      -86
Saved                 ichangetrackable_saved                Advanced                      -92
PageSaved             ichangetrackable_saved                Advanced                      -92
DeletedBy             ichangetrackable_deletedby            Advanced                      -81
PageDeletedBy         ichangetrackable_deletedby            Advanced                      -81
Deleted               ichangetrackable_deleted              Advanced                      -80
PageDeletedDate       ichangetrackable_deleted              Advanced                      -80
RouteSegment          iroutable_routesegment                EPiServerCMS_SettingsPanel    -3
PageURLSegment        iroutable_routesegment                EPiServerCMS_SettingsPanel    -3

So from the listing we can see in which group the property is by default displayed and the order it is using. With this information we could re-arrange the properties easily by changing the Order property value in our custom EditorDescriptors.

Listing the properties for BlockData

Similiar list as the PageData but for blocks.

PROPERTY NAME         INTERNAL NAME                         GROUP NAME                    ORDER

Name                  icontent_name                         EPiServerCMS_SettingsPanel    -4
ContentLink           icontent_contentlink                  Information                   -99
ParentLink            icontent_parentlink                   Information                   -97
ContentGuid           icontent_contentguid                                                
ContentTypeID         icontent_contenttypeid                Information                   -98
IsDeleted             icontent_isdeleted                    Information                   -93
Category              icategorizable_category               Information                   -69
Status                iversionable_status                   Advanced                      -95
IsPendingPublish      iversionable_ispendingpublish         Advanced                      -96
StartPublish          iversionable_startpublish             Advanced                      -81
StopPublish           iversionable_stoppublish              Advanced                      -79
Expire                iversionable_expire                   Information                   0
Shortcut              iversionable_shortcut                 Advanced                      0
Created               ichangetrackable_created              Advanced                      -80
CreatedBy             ichangetrackable_createdby            Advanced                      -87
Changed               ichangetrackable_changed              Advanced                      -78
SetChangedOnPublish   ichangetrackable_setchangedonpublish  Advanced                      -76
ChangedBy             ichangetrackable_changedby            Advanced                      -86
Saved                 ichangetrackable_saved                Advanced                      -92
DeletedBy             ichangetrackable_deletedby            Advanced                      -81
Deleted               ichangetrackable_deleted              Advanced                      -80

The BlockData has similiar properties as PageData but there are less properties.

Wrapping up

So now you know where from to get the “magic strings” and what properties you can control. As a side note your content type properties (the properties you have added in your contet type) are in the Properties property but you wouldn’t create a EditorDescriptor to control their display location but use the DisplayAttribute on the property on the content type.

I also decided to generate two class files that contain the mappings from “known” property name to the “internal name” so I or You don’t need to copy paste the values one by one to your own constants file.

Download constant files:

So with the constant files and with the information of property order we can then easily move for example the Shortcut property to the header in editor with the following code.

[EditorDescriptorRegistration(TargetType = typeof(ContentData))]
public class MoveShortcutToHeader : EditorDescriptor
{
    public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable attributes)
    {
        base.ModifyMetadata(metadata, attributes);

        // apply only to pagedata (the actual Model is the Castle proxy)
        if (metadata.Model is PageData)
        {
            // get the shortcut property
            ExtendedMetadata property = metadata.Properties.FirstOrDefault(m => 
            string.Compare(PageInternalEpiserverPropertyNameConstants.Shortcut, m.PropertyName, StringComparison.OrdinalIgnoreCase) == 0) as ExtendedMetadata;

            if (property != null)
            {
                property.GroupName = SystemTabNames.PageHeader;
                property.Order = -2;
            }
        }
    }
}

I also want to share the “EditorDescriptor” that I used to list the properties and “generate” the constant files. To get the “logging” you need to visit a page and block in the Episerver edit mode. Also you need to adjust your logging settings so that the debug level log entries are writen to your log file. Download the source here.

As usually sources are shared as is without any warranty and you can use them as you like.

If you missed blog post by Grzegorz Wiecheć “Additional header properties” and want to try out some move advanced features have a look at his post.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s