Shamrez Iqbal
Dec 18, 2014
  3632
(3 votes)

Adding StartPublishDate to PageTree tooltip

In my previous blog post I demonstrated how to customize the tooltip, but it turned out we needed to add the StartPublishDate property to the Tooltip, and it turned out that the item object in the javascript file did not contain this property, so time for some more hunting.

episerver/cms/Stores/contentstructure/This time I started out in the network tab of F12 showing only XHRs. Looking at the different requests I noticed most of them looked very similar so I had to dig through the contents until I found a call containing PageData and I eventually I found one.

image

Looking at the URL the data came from something called /Stores/contentstructure/ which ContentStructureStore is handling - which inherits from RestController.

A new customization point was needed. Looking at how this REST-controller retrieved data I noticed that the data was is converted into Model objects using something called ContentStoreModelCreator.

The ContentStoreModelCreator has a constructor which takes an enumerable of IModelTransform. This looked like a promising extension point, searching for implementers of this store I found PopulatePageDataModel. As in the previous post, I created a class inheriting from this class.

What PopulatePageDataModel basically does is, it has an array of property names in an array, and tries using the weakly-typed way of retrieving this data. My class added the “PageStartPublish” to the array, and modified the TransformInstance method to use my collection instead.

   public class MyPopulatePageDataModel : PopulatePageDataModel
    {
        private static readonly string[] PropertyNames = new string[]
    {
      "PageLanguageBranch",
      "PageExternalURL",
      "PageChildOrderRule",
      "PageSaved",
      "PageChangedBy",
      "PageCreated",
      "PageChanged",
      "PageTypeID",
      "PageVisibleInMenu",
      "PageShortcutType",
      "PageShortcutLink",
      "PageLinkURL",
      "PageStartPublish"
    };
        public override void TransformInstance(EPiServer.Core.IContent source, EPiServer.Cms.Shell.UI.Rest.Models.StructureStoreContentDataModel target, IModelTransformContext context)
        {
            PropertyDictionary properties = target.Properties;
            IContent content = source;
            foreach (string key in PropertyNames)
            {
                PropertyData propertyData = content.Property[key];
                if (propertyData != null)
                    properties.Add(key, propertyData.Value);
            }
        }
    }
The next step was to Intercept it in IOC, but the PopulatePageDataModel is marked as a singleton so instead of saying InterceptWith(i=>new CustomPopulatePageDataModel()) the object is created once in the module and its called with InterceptWith(i=>MyCustomPopulatePageDataModel);
  private static void ConfigureContainer(ConfigurationExpression container)
        {
            MyPopulatePageDataModel model = new MyPopulatePageDataModel();
            
            container.IfTypeMatches(type => type.Equals(typeof(PopulatePageDataModel))).InterceptWith(i => model);

           
            
            //Implementations for custom interfaces can be registered here.
        }
There are better ways of implementing a singleton but for the sake of demo I did it in the module, it’s possible that it might be possible to define it some other way in StructureMap as well. Now, when looking at the javascript-object being sent to the getItemToolTip we can see that the PageStartPublish is available and can be added to the tooltip. image
Dec 18, 2014

Comments

Please login to comment.
Latest blogs
Opti ID overview

Opti ID allows you to log in once and switch between Optimizely products using Okta, Entra ID, or a local account. You can also manage all your use...

K Khan | Jul 26, 2024

Getting Started with Optimizely SaaS using Next.js Starter App - Extend a component - Part 3

This is the final part of our Optimizely SaaS CMS proof-of-concept (POC) blog series. In this post, we'll dive into extending a component within th...

Raghavendra Murthy | Jul 23, 2024 | Syndicated blog

Optimizely Graph – Faceting with Geta Categories

Overview As Optimizely Graph (and Content Cloud SaaS) makes its global debut, it is known that there are going to be some bugs and quirks. One of t...

Eric Markson | Jul 22, 2024 | Syndicated blog

Integration Bynder (DAM) with Optimizely

Bynder is a comprehensive digital asset management (DAM) platform that enables businesses to efficiently manage, store, organize, and share their...

Sanjay Kumar | Jul 22, 2024