ljfio / Umbraco-InvisibleNodes

Make nodes 'invisible' in Umbraco
Apache License 2.0
1 stars 1 forks source link

Multiple ContentFinder #1

Closed alecrt closed 10 months ago

alecrt commented 11 months ago

I m8, I would use your package to organize event's landingpages but I have a problem with my very simple ContentFinder:

public Task<bool> TryFindContent(IPublishedRequestBuilder request)
        {
            var path = request.Uri.AbsolutePath;

            if (!path.EndsWith("/thankyou")) return
                    Task.FromResult(false);

            if (!_umbracoContextAccessor.TryGetUmbracoContext(out var umbracoContext))
            {
                return Task.FromResult(false);
            }
            var originalPath = path.Substring(0, path.LastIndexOf("/thankyou", StringComparison.OrdinalIgnoreCase));
            var landingPageContent = umbracoContext.Content!.GetByRoute(originalPath);

            if (landingPageContent is null || !landingPageContent.IsDocumentType("EventSimpleForms"))
                return Task.FromResult(false);

            request.SetPublishedContent(landingPageContent);
            request.TrySetTemplate("ThankYouPage");
            return Task.FromResult(true);
        }

As you can see I use it to create a virtual thankyou page for every landing page.

The issue I have is that umbracoContext.Content!.GetByRoute(originalPath) can't find the landing page content, when landing page nodes are under a hidden content node.

I did register my ContentFinder AFTER your one using Composition.

Any ideas? Thanks!

ljfio commented 11 months ago

Are you able to provide an example of the content tree structure along with the content types that you're hiding?

Does it look something like this:

Unfortunately, I believe the GetByRoute method of the IPublishedContentCache only looks at the URL segments manually and does not put the path through to the ContentFinder lifecycle again.

The solution here I think is a new release of the package, exposing the code used to traverse the content tree and locate the hidden node. You would just need to provide it with the path segments and the root node for the domain / site. I can provide an example of how to use it once I've built the new version?

alecrt commented 11 months ago

Yep, the content tree structure is exactly what you thought.

An exposed function to get the content by route on your IContentFinder could be an option, I just wonder if Umbraco has a specific method which use the routing pipeline.

ljfio commented 11 months ago

You should be able to upgrade to 1.0.1 to get access to the IInvisibleNodeLocator within your IContentFinder.

Using the root node, you should be able to pass in the path to the Locate method like so:

var contentCache = umbracoContext.Content;

string? culture = request.Culture;
var domain = request.Domain;

var root = domain is not null ? contentCache.GetById(domain.ContentId) : contentCache.GetAtRoot(culture).FirstOrDefault();

var landingPageContent = _invisibleNodeLocator.Locate(root, originalPath, culture);
alecrt commented 11 months ago

Thanks a lot. I will try as soon as possible!

Inviato da Outlook per iOShttps://aka.ms/o0ukef


Da: Luke Fisher @.> Inviato: Sunday, October 29, 2023 2:13:37 PM A: ljfio/Umbraco-InvisibleNodes @.> Cc: alecrt @.>; Author @.> Oggetto: Re: [ljfio/Umbraco-InvisibleNodes] Multiple ContentFinder (Issue #1)

You should be able to upgrade to 1.0.1 to get access to the IInvisibleNodeLocator within your IContentFinder.

Using the root node, you should be able to pass in the path to the Locate method like so:

var contentCache = umbracoContext.Content;

string? culture = request.Culture; var domain = request.Domain;

var root = domain is not null ? contentCache.GetById(domain.ContentId) : contentCache.GetAtRoot(culture).FirstOrDefault();

var landingPageContent = _invisibleNodeLocator.Locate(root, originalPath, culture);

— Reply to this email directly, view it on GitHubhttps://github.com/ljfio/Umbraco-InvisibleNodes/issues/1#issuecomment-1784106397, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAMSGTV3LIZLU7YV63M55XDYBZB7DAVCNFSM6AAAAAA6KHC66GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBUGEYDMMZZG4. You are receiving this because you authored the thread.Message ID: @.***>

ljfio commented 10 months ago

Hello @alecrt, I am going to close this issue. Please let me know if this has not resolved the problem for you. Thanks!