Custom resolving on a system without the Add-on Service installed
To customize the resolving process, you would normally create an Add-on and deploy it using the Add-on Service. However, if you have upgraded an old version of SDL Tridion Sites without installing the Add-on Service, you can still create and deploy your custom Resolver the old way. The first step, creating the Resolver class, is the same in the new setup, but the remaining steps are specific to an environment without an Add-on Service.
The following example illustrates which steps to take to customize resolving if you have no Add-on Service set up. 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.Resolving.PageTemplateResolver" assembly="Tridion.ContentManager.Publishing, Version=9.0.0.0, 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.Resolving.ComponentResolver" assembly="Tridion.ContentManager.Publishing, Version=9.0.0.0, 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 3: adding custom configuration (optional)
-
If your custom resolver class requires custom configuration, SDL Tridion Sites expects to find such configuration in the same Tridion.ContentManager.config file, in the section named as specified in the code. To create and specify such a section, do the following:
In the
<configSections>section at the top of the file, add asectionelement, provide a name, and set thetypeattribute to a class that can handle the contents of the section. For example, if the section contains a simple named property, use the default .NET classSystem.Configuration.NameValueSectionHandler:<section name="My.Tridion.CustomResolving" type="System.Configuration.NameValueSectionHandler" />Next, at the bottom of the file, add a configuration section with the name you specified and fill it with content that the class you specified can handle. In this example, the section contains an
addelement with akeyand avalueattribute:<My.Tridion.CustomResolving> <add key="schemaTitles" value="FullArticleSchema" /> </My.Tridion.CustomResolving>
- Step 4: Applying your changes
-
From your list of Windows Services, restart all Windows services that start with
SDL Web Content Manager. Also restart IIS and the SDL Web Content Manager COM+ application. This applies your changes.