Skip to content

Default IRelatedLinksToRenderingConverterScoped throws Method not found: 'Umbraco.Core.Models.IPublishedContent Umbraco.Web.Models.RelatedLinkBase.get_Content()'. #3

@bmcdavid

Description

@bmcdavid

Work around is to register a custom one noted below:

    [StartupModule(typeof(DotNetStarter.RegisterConfiguration))]
    public class CustomConfigure : ILocatorConfigure
    {
        public void Configure(ILocatorRegistry registry, IStartupEngine engine)
        {
            registry.Add<IRelatedLinksToRenderingConverterScoped, CustomRelatedLinksToRenderingConverter>(lifetime: LifeTime.Scoped);
        }
    }

    public class CustomRelatedLinksToRenderingConverter : IRelatedLinksToRenderingConverterScoped
    {
        private readonly IRenderingAliasResolver _DescriptorResolver;
        private readonly IRenderingCreatorScoped _RenderingCreator;

        public CustomRelatedLinksToRenderingConverter(IRenderingAliasResolver publishedContentAliasResolver, IRenderingCreatorScoped renderingCreatorScoped)
        {
            _DescriptorResolver = publishedContentAliasResolver;
            _RenderingCreator = renderingCreatorScoped;
        }

        public virtual IList<T> ConvertLinks<T>(IEnumerable<RelatedLink> relatedLinks, ICollection<Type> allowedTypes)
        {
            relatedLinks = relatedLinks ?? Enumerable.Empty<RelatedLink>();
            var list = new List<T>();
            var aliases = _DescriptorResolver.ResolveTypes(allowedTypes);

            foreach (var item in relatedLinks)
            {
                if (aliases.Any(a => a == item.Content?.DocumentTypeAlias))
                {
                    T content = (T)_RenderingCreator.GetCreator<IPublishedContent>(item.Content.DocumentTypeAlias).Invoke(item.Content);
                    var relatedContentLink = content as ISetRelatedLink;
                    relatedContentLink?.SetLink(item); // give the link data to the model

                    list.Add(content);
                }
            }

            return list;
        }
    }

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions