London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
AI OnAI Off
London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!
Hi Folks,
We are looking at modifying the URL generator pipeline to modify the url for certain content types. We have a new pipeline step registered, but when the step is hit, I would expect the context.ContentLink to be the current page I am generating the url for., but it is always the Start Page. Looking at the PreferredUrlGeneratorPipelineStep in the same pipeline, it looks like it is using the current page ContentReference and I would like to do the same. Anyone know what I am doing wrong?
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next) { return builder => { var generatorPipelineRegistry = builder.ApplicationServices.GetService<UrlGeneratorPipelineRegistry>(); var resolverPipelineRegistry = builder.ApplicationServices.GetService<UrlResolverPipelineRegistry>(); var startPageDefaultMode = GetGeneratorDefinition("StartPage", RouteContextMode.Default); startPageDefaultMode.Insert( startPageDefaultMode.FindIndex(x => x.Type == typeof(PreferredUrlGeneratorPipelineStep)), new PipelineStepDefinition { Type = typeof(ProductDetailGeneratorStep) }); PipelineDefinition GetGeneratorDefinition(string name, RouteContextMode contextMode) { return generatorPipelineRegistry.All.FirstOrDefault(x => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase) && x.ContextMode == contextMode); } next(builder); }; }
public class ProductDetailGeneratorStep : IUrlGeneratorPipelineStep { public RoutingState Generate(UrlGeneratorContext context, UrlGeneratorOptions options) { //get content var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>(); if (contentLoader.TryGet(context.ContentLink, out ProductBase product)) { //do stuff and update url } // Tells the pipeline to continue generating next segment in the URL return RoutingState.Continue; } }