Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V15: Apply content type filtering to self too #17581

Open
wants to merge 2 commits into
base: v15/dev
Choose a base branch
from

Conversation

elit0451
Copy link
Member

Details

  • Calling content.DescendantsOrSelfOfType(...) or content.AncestorsOrSelf(..., "contentTypeAlias") wasn't taking the content type alias into consideration for the self node - this PR fixes that.

Test

  • Create 2 simple document types with template - give one of them a colourful icon so you can easily distinguish it in the content tree;
  • Create a nested content tree where you mix the content types;
  • Use the following code in both templates and just modify the value of the content type alias:
@using Umbraco.Cms.Web.Common.PublishedModels;
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
@using Umbraco.Cms.Core.PublishedCache
@using Umbraco.Cms.Core.Routing
@using Umbraco.Cms.Core.Services.Navigation
@using Umbraco.Extensions

@inject IPublishedValueFallback PublishedValueFallback
@inject IPublishedUrlProvider PublishedUrlProvider
@inject IVariationContextAccessor VariationContextAccessor
@inject IPublishedContentCache PublishedContentCache
@inject IDocumentNavigationQueryService DocumentNavigationQueryService
@{
	Layout = null;
}

<h1>Hello from "@Model.Value("title")"</h1>

@{
	var ancestorsOrSelfOfType = Model.AncestorsOrSelf(PublishedContentCache, DocumentNavigationQueryService, "page1").Where(x => x.IsVisible(PublishedValueFallback)).ToArray();
	
	var descendantsOrSelfOfType = Model.DescendantsOrSelfOfType(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, "page1").Where(x => x.IsVisible(PublishedValueFallback)).ToArray();
	
	var siblingsOrSelfOfType = Model.SiblingsAndSelfOfType(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, "page1").Where(x => x.IsVisible(PublishedValueFallback)).ToArray();

	var selection = ancestorsOrSelfOfType; @* CHANGE THIS *@
 }

@if (selection?.Length > 0)
{
    @foreach (var item in selection)
    {
        <li>
	    <a href="@item.Url(PublishedUrlProvider)">@item.Name</a>
	</li>
    }
}
  • Verify that the different content type aliases include/exclude self from the result, i.e. that the content type filtering is applied to self too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant