Extending the getContact pipeline
For custom personalization tokens to be replaced in the online Preview mode, extend the getContact
pipeline.
This topic applies to Sitecore versions 9.0.1 and later.
To extend the getContact
pipeline:
-
Create a new pipeline processor. See example below.
-
Deploy the assembly with your pipeline processor to all CM and DDS instances.
-
Navigate to the
\App_Config\Sitecore\EmailExperience
directory. -
Create a configuration patch file, in which you replace the
Sitecore.Modules.EmailCampaign.Core.Pipelines.GetContact.GetContact
pipeline processor in thegetContact
pipeline in Sitecore.EmailExperience.Core.config file.
The following example illustrates how to extend the getContact
pipeline:
using System;
using System.Linq;
using Sitecore;
using Sitecore.Data;
using Sitecore.Framework.Conditions;
using Sitecore.Modules.EmailCampaign.Core.Contacts;
using Sitecore.Modules.EmailCampaign.Core.Pipelines.GetContact;
namespace MyNamespace
{
public class GetContact
{
private readonly IContactService _contactService;
public GetContact([NotNull] IContactService contactService)
{
Condition.Requires(contactService, nameof(contactService)).IsNotNull();
_contactService = contactService;
}
public void Process([NotNull] GetContactPipelineArgs args)
{
Condition.Requires(args, nameof(args)).IsNotNull();
if (args.ContactIdentifier == null && ID.IsNullOrEmpty(args.ContactId))
{
throw new ArgumentException("Either the contact identifier or the contact id must be set");
}
string[] facetKeys = args.FacetKeys.Concat(new[]
{
"CustomFacetName" // the custom facet name
}).ToArray();
args.Contact =
args.ContactIdentifier != null ?
_contactService.GetContact(args.ContactIdentifier, facetKeys)
:
_contactService.GetContact(args.ContactId, facetKeys);
}
}
}