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

Merged

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.

…ugfix/apply-content-type-filtering-on-self-too
…v15/bugfix/apply-content-type-filtering-on-self-too
@elit0451 elit0451 changed the base branch from v15/dev to release/15.1 November 26, 2024 07:41
Copy link
Member

@Zeegaan Zeegaan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, tests good 🚀
will merge when tests are happy 😁

@Zeegaan Zeegaan merged commit 334cb47 into release/15.1 Nov 26, 2024
16 of 17 checks passed
@Zeegaan Zeegaan deleted the v15/bugfix/apply-content-type-filtering-on-self-too branch November 26, 2024 12:14
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.

2 participants