IUrlToEntityTokenMapper

Map URLs and entity tokens to synchronize the tree elements and the browser view in the CMS Console.

Using the IUrlToEntityTokenMapper interface you can associate URLs and entity tokens, mapping both ways: URLs to entity tokens and entity tokens to URLs.

Unlike data URL mappers that map only data items to URLs, URL-to-entity-token mappers enable synchronization between the browser view and the tree for any tree element in the CMS Console.

Besides, since a URL does not necessarily have to be a public URL, the mapper can be used for custom previews of tree elements in the browser view as, for example, the "Server Log" or "Websites" elements do in the "System" and "Content" perspectives respectively.

To use URL-to-entity-token mappers, you should:

  1. Create a class implementing the Composite.C1Console.Elements.IUrlToEntityTokenMapper interface.
    namespace Composite.C1Console.Elements
    {
        public interface IUrlToEntityTokenMapper
        {
            string TryGetUrl(EntityToken entityToken);
            EntityToken TryGetEntityToken(string url);
        }
    }
    
  2. Register an instance of the class at the application startup:
    UrlToEntityTokenFacade.Register(new CustomUrlToEntityTokenMapper());

Using IUrlToEntityTokenMapper

In the following example, you will map an internal URL pointing to the server log to the entity token "system.server.log".

Mapping a URL to an entity token

using Composite.C1Console.Elements;
using Composite.C1Console.Security;
using Composite.C1Console.Trees;
using Composite.Core.WebClient;

namespace CustomServerLogPreview
{
    internal class ServerLogUrlToEntityTokenMapper : IUrlToEntityTokenMapper
    {
        public string TryGetUrl(EntityToken entityToken)
        {
            var castedEntityToken = entityToken as TreeSimpleElementEntityToken;

            if (castedEntityToken == null || castedEntityToken.Id != "system.server.log")
            {
                return null;
            }

            return UrlUtils.Combine(UrlUtils.AdminRootPath, "/content/views/log/log.aspx?hideToolbar=true");
        }

        public EntityToken TryGetEntityToken(string url)
        {
            return null;
        }

        public BrowserViewSettings TryGetBrowserViewSettings(EntityToken entityToken, bool showPublishedView)
        {
            return null;
        }

    }

}

Download the code

Creating and registering an instance of the mapper

using Composite.C1Console.Elements;
using Composite.Core.Application;

namespace CustomServerLogPreview
{
    [ApplicationStartup]
    public static class StartupHandler
    {     
        public static void OnBeforeInitialize()
        {

        }

        public static void OnInitialized()
        {
            UrlToEntityTokenFacade.Register(new ServerLogUrlToEntityTokenMapper());
        }
    }
}

Download the code

Requirements:

C1 CMS version 5.0 or later