Custom resolving
Customizing the resolving process involves manipulating the list of items to publish that results from a publish action.
The following example illustrates which steps to take to customize resolving. In this example, we want to remove all Components from the list of resolved items, unless they are based on certain Schemas. These Schemas are configured in a custom configuration section in the Content Manager configuration file.
- Step 1: creating a custom resolver class in .NET
-
To start, implement your business logic in a custom resolver class. This class implements the
IResolverinterface, found in the Tridion.ContentManager.Publishing.Resolving namespace.In this example, the custom resolver reads a set of Schemas, loops through the resolved items as produced by Content Manager, and excludes all Components based on a Schema not listed in the set of Schemas.public class MyResolver : IResolver { // Get the value of schemaTitles from the custom configuration section for this custom resolver private string[] SCHEMA_TITLES = { "MySchema1", "MySchema2", "MySchema3" }; #region IResolver Members // This Resolve method executes after the default resolver has done its job and produced a set of resolved items. public void Resolve(IdentifiableObject item, ResolveInstruction instruction, PublishContext context, ISet<ResolvedItem> resolvedItems) { // If the item being resolved currently is not a Component, skip it. if (!(item is Component)) { return; } else { // Also skip the item if it is a Component, but it is not based on a configured Schema. Component component = item as Component; if (ConfigContains(component.Schema.Title)) { // If this is a Component based on one of the configured Schemas, loop over the list of resolved items. // Assemble a list of those items that meet one or more of the following conditions: // 1. Not a Component // 2. Identical to the current item // 3. Based on a Schema that is _not_ listed among those configured. List<ResolvedItem> tempItems = new List<ResolvedItem>(); foreach (ResolvedItem resolvedItem in resolvedItems) { if (!(resolvedItem.Item is Component) || resolvedItem.Item.Id == item.Id || !ConfigContains(((Component)resolvedItem.Item).Schema.Title)) { tempItems.Add(resolvedItem); } // Now empty the resolvedItems array and copy all the saved items into it. resolvedItems.Clear(); foreach (ResolvedItem tempResolvedItem in tempItems) { resolvedItems.Add(tempResolvedItem); } } } } } #endregion }Create an assembly from this .NET class and add it to the Global Assembly Cache (GAC).
- Step 2: extending Content Manager with your custom resolver
-
Now that you have your custom resolver set up, you can make the Resolver available to Content Manager by configuring your Resolver in the Content Manager configuration file on the Content Manager server, Tridion.ContentManager.config. To do so, do the following:
- On your Content Manager server, access the config\ subfolder of
%TRIDION_HOME%. - Open Tridion.ContentManager.config for editing.
- In this file, find the
<resolving>section, which contains a<mappings>section with a number ofaddelements, one for each publishable item type. Here is one suchaddelement:<add itemType="Tridion.ContentManager.CommunicationManagement.PageTemplate"> <resolvers> <add type="Tridion.ContentManager.Publishing.Legacy.Resolving.PageTemplateResolver" assembly="Tridion.ContentManager.Publishing.Legacy, Version=5.4.0.1110, Culture=neutral, PublicKeyToken=360aac4d3354074b"/> </resolvers> </add>The
itemTypeattribute indicates the type of items being resolved (Page Template in this case) and the<resolvers>element contains a list of resolvers for this type (by default, just the one standard resolver that SDL Tridion Sites ships with), specifying the class and assembly information. - Add a new
addelement below the one already present. For example, to add theMyResolverclass above to the list of resolvers for theComponentitem type, add a newaddelement inside the<resolvers>and specify the class and assembly information:<add itemType="Tridion.ContentManager.ContentManagement.Component"> <resolvers> <add type="Tridion.ContentManager.Publishing.Legacy.Resolving.ComponentResolver" assembly="Tridion.ContentManager.Publishing.Legacy, Version=5.4.0.1110, Culture=neutral, PublicKeyToken=360aac4d3354074b"/> <add type="MyResolver" assembly="MyCompany.Tridion.CustomResolving, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e0565a33f351b321"/> </resolvers> </add> - Save and close Tridion.ContentManager.config.
- On your Content Manager server, access the config\ subfolder of
- Step 4: Applying your changes
-
From your list of Windows Services, restart all Windows services that start with
Tridion Content Manager. Also restart IIS and the SDL Tridion Sites Content Manager COM+ application. This applies your changes.