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: Implement content type filtering for in-memory navigation structure #17456

Conversation

elit0451
Copy link
Contributor

@elit0451 elit0451 commented Nov 7, 2024

Details

  • Adding content type key property to NavigationNode and loading it from the DB when refreshing the content of the navigation structure;
    • Updating the SQL query in FetchNavigationDtos();
    • Updating the implementation to pass in a content type when adding a node to the navigation str.
  • Building a map of content type alias to key so we can look up the aliases which are being queried;
  • Adding generics to ContentNavigationServiceBase and updating its extending classes;
  • Adding TryGetChildrenKeysOfType(), TryGetDescendantsKeysOfType(), TryGetAncestorsKeysOfType(), TryGetSiblingsKeysOfType() and TryGetRootKeysOfType();
  • Adding unit and integration tests + test data refactoring;
  • Fix PublishedContentExtensions to use the new filtering methods (more performant) instead of using the cache to resolve the IPublishedContent items and then apply content type filtering;
  • Adding .Parent() friendly extension method, without a specific type.

Test

  • Make sure all new tests pass;
  • Using any of the affected PublishedContentExtensions methods in a document type template hasn't changed the functionality;
    • Keep in mind that you need to create a content tree with different content types (with template) to see the filtering take effect.
  • To test the new .Parent() from the FriendlyPublishedContentExtensions - you can add <h1>Hello from "@Model.Parent().Name"</h1> to a child template.

Template example for SiblingsOfType()

@using Umbraco.Cms.Web.Common.PublishedModels;
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
@using Umbraco.Cms.Core
@using Umbraco.Cms.Core.Models.PublishedContent
@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;
}

<h2>Experiments with extensions</h2>

@{ var selection = Model.SiblingsOfType(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService, "contentPage").Where(x => x.IsVisible(PublishedValueFallback)).ToArray(); }

@* Ensure that the Current Page has siblings *@
@if (selection?.Length > 0)
{
    @foreach (var item in selection)
    {
        <li>
	    <a href="@item.Url(PublishedUrlProvider)">@item.Name</a>
	</li>
    }
}

…v15/feature/implement-content-type-filtering-for-navigation-str
…v15/feature/implement-content-type-filtering-for-navigation-str
@Zeegaan
Copy link
Member

Zeegaan commented Nov 11, 2024

Looks good, works great 🚀

@Zeegaan Zeegaan merged commit c26016b into release/15.0 Nov 11, 2024
11 of 15 checks passed
@Zeegaan Zeegaan deleted the v15/feature/implement-content-type-filtering-for-navigation-str branch November 11, 2024 11:00
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.

None yet

3 participants