Few editors asked us if there is a possibility to display list of all content (both block and pages) referenced by currently edited page. I’ve looked in the edit mode Tools menu, Publish menu and context menu actions. The only place where I found this functionality was “Move to trash” command. When editor is removing the page the confirmation dialog will list all references to deleted page.

contentreferewnce move to trash

Related content dialog

I need simpler solution, so I decided to prepare similar functionality by reusing “move to trash” dialog code and place it under the “Publish” menu.
To prepare new command in EPiServer Edit mode we need to implement three Javascript files:

  • command initializer – registers new command in specific area,
  • command provider – returns the list of commands; consumed by command initializer,
  • command – action; displays the related content dialog window.

All of above files will be created under modules/commands/samples directory.
contentreferences directory structure
We will also require modules.config file with necessary configuration under commands directory.

Command initializer

The initializer resolves globalcommandregistry object and registers the command provider under specific key. This registration code should be invoked inside initialize metod. The “Key” is the area of registration. In this example we will use “epi.cms.publishmenu”.

Initializer should be executed automatically by the EPiServer framework. To ensure this, We need to set proper dependencies inside modules.config under clientResources and clientModule sections. Our initializer should be executed when all of edit mode components are initialized. To achieve this we will add dependency on CMS module.

Command provider

Command provider inherits from _CommandProviderMixin. We need to add new RelatedPagesCommand to the list of commands in constructor. This will be the only one command of this provider.

Command

Command has few properties like name, label, tooltip and one mandatory method: “_execute”. This method will be used as an action of the command.  Inside RelatedPages command we are using “epi-cms/widget/ContentReferences” widget to show the dialog.

Last small improvement was the References icon contentreference icon. I found list of all default icons in CommonIcons.less file.

Below are the screenshots of extended publish menu
contentreferences publish menu
…and the references dialog list result
contentreferences preview

If you would like to use “Tools menu” instead of Publish menu just change the registration key of the command initializer. In current example I’m using “epi.cms.publishmenu” while for Tools it should be “epi.cms.contentdetailsmenu“:

After applying this changes command will appear in Tools menu:
contentreference tools menu

Described command initialization pattern will not work in older EPiServer versions (7.0, 7.0.1)

The full source code is on Github.