Documentation Center

Extension example: adding a new column to a list view

In this example, you modify the data returned by a GetList call and a GetListXml call to the Core Service by adding Schema information. With the Event Handler implemented, you can then add a column to a list view to show the new Schema information.

Procedure

  1. First, create your Extension in the form of a .NET class that extends the TcmExtension class. This class includes the following:
    using System.Linq;
    using Tridion.ContentManager;
    using Tridion.ContentManager.ContentManagement;
    using Tridion.ContentManager.Extensibility;
    using Tridion.ContentManager.Extensibility.Events;
    
    namespace ListExtender
    {
      [TcmExtension("MyListEventHandlerExtension")]
      public class ListExtension : TcmExtension
  2. In order to modify the data returned by the GetList method, we intercept its response, which is a list of Repository Local Objects. To do so, we subscribe to the event of a specific type of Organizational Item (a Folder, say, or a Bundle) fetching a list of its contents. Specifically, we specify to check this in the Processed Event Phase, a phase in which the list will be available. The code for this subscription is as follows:
    public ListExtension()
    {
      Subscribe();
    }
    
    public void Subscribe()
    {
      EventSystem.Subscribe<OrganizationalItem, GetListEventArgs<OrganizationalItemItemsFilter>>(CUSTOMMETHOD, EventPhases.Processed);
    }

    where CUSTOMMETHOD is your custom method that processes the list and adds a new property. For the sake of this example, we create a custom method that we call AddMetadataSchemaTitle, which adds the name of the Metadata Schema on which an item is based as a new custom property.

  3. Implement the custom method. For example, our AddMetadataSchemaTitle method implements the following functionality:
    1. It iterates through the items in the list.
    2. For each item, it checks if the item has a Metadata Schema defined. Note that for most items, this check means fully loading the item.
    3. If the item has a Metadata Schema, the title of that Metadata Schema is stored in an extension property called SchemaTitle.

    The extension properties will be added to the existing list results and sent along with them back to the client (both when the client is requesting data objects and when it is requesting an XML list). Here is the AddMetadataSchemaTitle method:

    private void AddMetadataSchemaTitle(OrganizationalItem subject, GetListEventArgs<OrganizationalItemItemsFilter> e, EventPhases phase)
    {
      foreach (RepositoryLocalObject item in e.ListItems.OfType<RepositoryLocalObject>())
      {
        if (item.MetadataSchema != null)
        {
          item.ExtensionProperties.Add("SchemaTitle", item.MetadataSchema.Title);
        }
      }
    }
  4. This concludes the implementation of your Event Handler class. Save your class to a .cs file (ListExtension.cs in this example) and add it to your Visual Studio solution. Compile to create a new .NET assembly (ListExtender.dll in this example).
  5. If this Event Handler constitutes an Add-on feature to your product all by itself, or if this Event Handler is part of a larger Add-on feature for which you have not yet created an Add-on ZIP file, create a new ZIP file for your Add-on feature.
  6. Add your Event Handler .NET assembly file to the Add-on feature ZIP file to which it belongs. Place it in a new root-level folder in the ZIP file that you call ListExtender\.
  7. Decide in which SDL Tridion Sites user interface or user interfaces you want the extended list to appear (Content Manager Explorer, Experience Manager, your own custom UI), and in which views of the user interface you want the list to be extended. In this example, we add the extension to Content Manager Explorer only, and only to its item select dialogs (so not to the ordinary list view on the main screen).
  8. Create an initial configuration file for your Editor as explained elsewhere in the documentation and call it ListExtenderEditor.config.
  9. In the extensions section, locate the ext:editorextensions section. Inside this section, create or find an ext:editorextension element with its target attribute set to the identifier of the user interface you want to extend. For example, to extend Content Manager Explorer, find <ext:editorextension target="CME">.
  10. Within this ext:editorextension element, ensure the presence of an ext:lists child subelement, and within that ext:lists element, add the extension configuration in the form of an ext:add child element, as follows:
    <ext:add>
      <ext:extension name="EXTENSIONNAME" assignid="EXTENSIONID">
        <ext:listDefinition>
          <ext:selectornamespaces>
            <list:namespace prefix="ext" uri="http://www.tridion.com/ContentManager/R5/Extension" />
          </ext:selectornamespaces>
          <ext:columns>
            <list:column id="COLUMNID type="data" title="COLUMNHEADERNAME" selector="XPATH" />
          </ext:columns>
        </ext:listDefinition>
        <ext:apply>
          <ext:view name="VIEWNAME">
            <ext:control id="FilteredItemList" />
          </ext:view>
        </ext:apply>
      </ext:extension>
    </ext:add>
    where:
    • EXTENSIONNAME is a name for your extension, for example, MyColumnExtender
    • EXTENSIONID is a unique identifier for your extension, for example, MyColumnExtenderID
    • COLUMNID is a unique identifier for the new column in your view, for example, MyColumnID
    • COLUMNHEADERNAME is the label that will appear in the user interface as the column header; in our example, Schema would be a good value
    • XPATH is the XPath that gets the value to put in this column; in our example, this would be @ext:SchemaTitle, referring to the new SchemaTitle property we have added.
    • VIEWNAME is the name of the view in which the list should show this additional column; in our example, this would be ItemSelectDialogPopup.
  11. If you wish, specify one or more of the following additional attributes in the list:column element:
    Attribute nameValue description
    widthThe default width in pixels of the column when the view loads initially. For example, to set initial width to 60 pixels, set this attribute's value to 60px.
    enableresizingEnables users to change the width of this column, if set to true.
    enablesortingEnables users to sort the data in this column, if set to true.
    enablefilteringEnables users to filter the data this column, if set to true.
    columnfilter
    Set to one of the following values:
    value
    The user can filter the column on specific values. Use this value if you expect your column to contain only a small number of different values.
    group
    The user can filter the column on groups of values, as automatically generated by SDL Tridion Sites. Use this value if you expect your column to contain a large number of different values.
    daterange
    If your column contains dates, this filter enables users to filter on a specific date range.
  12. Save and close ListExtenderEditor.config.
  13. Add your Editor folder tree to the ListExtender\ folder in the same Add-on package ZIP file to which you already added ListExtender.dll.
  14. Extract the Add-on feature manifest file, manifest.json, from the Add-on feature ZIP file, and open it for editing.
  15. In the extensions array, insert the following JSON fragment:
    {
      "name": "ListExtender",
      "type": "CMEventHandler",
      "properties": {
        "assemblyFileSource": "ListExtender\\ListExtender.dll"
      }
    },
    {
      "name":"ListExtenderEditor",
      "type": "UIEditor",
      "properties": {
        "name": "ListExtenderEditor",
        "contentFolder": "ListExtender\\Editor",
        "configurationPath": "ListExtender\\Editor\\Configuration\\ListExtenderEditor.config",
        "assembliesFolder": "ListExtender\\Editor\\Assemblies",
        "globalResourcesFolder": "ListExtender\\Editor\\Resources"
      }
    }
  16. Save and close the modified manifest.json file and update it in the Add-on ZIP file.
  17. Deploy or redeploy the Add-on feature ZIP file from the Add-ons screen in Content Manager Explorer.
    Your extension now shows up in the user interfaces and views you specified.