Shamrez Iqbal
Dec 18, 2014
  3734
(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
Copy Optimizely SaaS CMS Settings to ENV Format Via Bookmarklet

Do you work with multiple Optimizely SaaS CMS instances? Use a bookmarklet to automatically copy them to your clipboard, ready to paste into your e...

Daniel Isaacs | Dec 22, 2024 | Syndicated blog

Increase timeout for long running SQL queries using SQL addon

Learn how to increase the timeout for long running SQL queries using the SQL addon.

Tomas Hensrud Gulla | Dec 20, 2024 | Syndicated blog

Overriding the help text for the Name property in Optimizely CMS

I recently received a question about how to override the Help text for the built-in Name property in Optimizely CMS, so I decided to document my...

Tomas Hensrud Gulla | Dec 20, 2024 | Syndicated blog

Resize Images on the Fly with Optimizely DXP's New CDN Feature

With the latest release, you can now resize images on demand using the Content Delivery Network (CDN). This means no more storing multiple versions...

Satata Satez | Dec 19, 2024