V15: Update navigation references in Partial Views (#17613)

* Inject and pass-in parameters to use the respective PublishedContentExtensions methods

* Fix view comments

* Other fixes
This commit is contained in:
Elitsa Marinovska
2024-11-25 10:30:43 +01:00
committed by GitHub
parent 75ba6b7492
commit 4a19d899dd
9 changed files with 48 additions and 28 deletions

View File

@@ -1,16 +1,19 @@
@using Umbraco.Cms.Core.PublishedCache
@using Umbraco.Cms.Core.Routing
@using Umbraco.Extensions
@using Umbraco.Cms.Core.Services.Navigation
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
@inject IPublishedContentCache PublishedContentCache
@inject IDocumentNavigationQueryService DocumentNavigationQueryService
@inject IPublishedUrlProvider PublishedUrlProvider
@*
This snippet makes a breadcrumb of parents using an unordered HTML list.
How it works:
- It uses the Ancestors() method to get all parents and then generates links so the visitor can go back
- It uses the Ancestors method to get all parents and then generates links so the visitor can go back
- Finally it outputs the name of the current page (without a link)
*@
@{ var selection = Model?.Content.Ancestors().ToArray(); }
@{ var selection = Model?.Content.Ancestors(PublishedContentCache, DocumentNavigationQueryService).ToArray(); }
@if (selection?.Length > 0)
{

View File

@@ -1,16 +1,19 @@
@using Umbraco.Cms.Core.PublishedCache
@using Umbraco.Cms.Core.Routing
@using Umbraco.Extensions
@using Umbraco.Cms.Core.Services.Navigation
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
@inject IPublishedContentCache PublishedContentCache
@inject IDocumentNavigationQueryService DocumentNavigationQueryService
@inject IPublishedUrlProvider PublishedUrlProvider
@*
This snippet makes a list of links to the of parents of the current page using an unordered HTML list.
How it works:
- It uses the Ancestors() method to get all parents and then generates links so the visitor can go back
- It uses the Ancestors method to get all parents and then generates links so the visitor can go back
- Finally it outputs the name of the current page (without a link)
*@
@{ var selection = Model?.Content.Ancestors().ToArray(); }
@{ var selection = Model?.Content.Ancestors(PublishedContentCache, DocumentNavigationQueryService).ToArray(); }
@if (selection?.Length > 0)
{

View File

@@ -1,8 +1,11 @@
@using Umbraco.Cms.Core
@using Umbraco.Cms.Core.Models.PublishedContent
@using Umbraco.Cms.Core.PublishedCache
@using Umbraco.Cms.Core.Routing
@using Umbraco.Extensions
@using Umbraco.Cms.Core.Services.Navigation
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
@inject IVariationContextAccessor VariationContextAccessor
@inject IPublishedContentCache PublishedContentCache
@inject IDocumentNavigationQueryService DocumentNavigationQueryService
@inject IPublishedValueFallback PublishedValueFallback
@inject IPublishedUrlProvider PublishedUrlProvider
@*
@@ -13,7 +16,7 @@
- It then generates links so the visitor can go to each page
*@
@{ var selection = Model?.Content.Children.Where(x => x.IsVisible(PublishedValueFallback)).ToArray(); }
@{ var selection = Model?.Content.Children(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService).Where(x => x.IsVisible(PublishedValueFallback)).ToArray(); }
@if (selection?.Length > 0)
{

View File

@@ -1,8 +1,11 @@
@using Umbraco.Cms.Core
@using Umbraco.Cms.Core.Models.PublishedContent
@using Umbraco.Cms.Core.PublishedCache
@using Umbraco.Cms.Core.Routing
@using Umbraco.Extensions
@using Umbraco.Cms.Core.Services.Navigation
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
@inject IVariationContextAccessor VariationContextAccessor
@inject IPublishedContentCache PublishedContentCache
@inject IDocumentNavigationQueryService DocumentNavigationQueryService
@inject IPublishedValueFallback PublishedValueFallback
@inject IPublishedUrlProvider PublishedUrlProvider
@*
@@ -14,7 +17,7 @@
- It then generates links so the visitor can go to each page
*@
@{ var selection = Model?.Content.Children.Where(x => x.IsVisible(PublishedValueFallback)).OrderByDescending(x => x.CreateDate).ToArray(); }
@{ var selection = Model?.Content.Children(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService).Where(x => x.IsVisible(PublishedValueFallback)).OrderByDescending(x => x.CreateDate).ToArray(); }
@if (selection?.Length > 0)
{

View File

@@ -1,8 +1,11 @@
@using Umbraco.Cms.Core
@using Umbraco.Cms.Core.Models.PublishedContent
@using Umbraco.Cms.Core.PublishedCache
@using Umbraco.Cms.Core.Routing
@using Umbraco.Extensions
@using Umbraco.Cms.Core.Services.Navigation
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
@inject IVariationContextAccessor VariationContextAccessor
@inject IPublishedContentCache PublishedContentCache
@inject IDocumentNavigationQueryService DocumentNavigationQueryService
@inject IPublishedValueFallback PublishedValueFallback
@inject IPublishedUrlProvider PublishedUrlProvider
@*
@@ -14,14 +17,14 @@
- It then generates links so the visitor can go to each page
*@
@{ var selection = Model?.Content.Children.Where(x => x.IsVisible(PublishedValueFallback)).OrderBy(x => x.Name).ToArray(); }
@{ var selection = Model?.Content.Children(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService).Where(x => x.IsVisible(PublishedValueFallback)).OrderBy(x => x.Name).ToArray(); }
@if (selection?.Length > 0)
{
<ul>
@foreach (var item in selection)
{
<li><a href="@item.Url(PublishedUrlProvider))">@item.Name</a></li>
<li><a href="@item.Url(PublishedUrlProvider)">@item.Name</a></li>
}
</ul>
}

View File

@@ -1,9 +1,11 @@
@using Umbraco.Cms.Core
@using Umbraco.Cms.Core.Models.PublishedContent
@using Umbraco.Cms.Core.PublishedCache
@using Umbraco.Cms.Core.Routing
@using Umbraco.Extensions
@using Umbraco.Cms.Core.Services.Navigation
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
@inject IVariationContextAccessor VariationContextAccessor
@inject IPublishedContentCache PublishedContentCache
@inject IDocumentNavigationQueryService DocumentNavigationQueryService
@inject IPublishedValueFallback PublishedValueFallback
@inject IPublishedUrlProvider PublishedUrlProvider
@*
@@ -13,7 +15,7 @@
(You can find the alias of your Document Type by editing it in the Settings section)
*@
@{ var selection = Model?.Content.Children<IPublishedContent>(VariationContextAccessor).Where(x => x.IsVisible(PublishedValueFallback)).ToArray(); }
@{ var selection = Model?.Content.Children<IPublishedContent>(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService).Where(x => x.IsVisible(PublishedValueFallback)).ToArray(); }
@if (selection?.Length > 0)
{

View File

@@ -1,8 +1,11 @@
@using Umbraco.Cms.Core
@using Umbraco.Cms.Core.Models.PublishedContent
@using Umbraco.Cms.Core.PublishedCache
@using Umbraco.Cms.Core.Routing
@using Umbraco.Extensions
@using Umbraco.Cms.Core.Services.Navigation
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
@inject IVariationContextAccessor VariationContextAccessor
@inject IPublishedContentCache PublishedContentCache
@inject IDocumentNavigationQueryService DocumentNavigationQueryService
@inject IPublishedValueFallback PublishedValueFallback
@inject IPublishedUrlProvider PublishedUrlProvider
@*
@@ -11,7 +14,7 @@
It also highlights the current active page/section in the navigation with the CSS class "current".
*@
@{ var selection = Model?.Content.Root().Children.Where(x => x.IsVisible(PublishedValueFallback)).ToArray(); }
@{ var selection = Model?.Content.Root(PublishedContentCache, DocumentNavigationQueryService).Children(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService).Where(x => x.IsVisible(PublishedValueFallback)).ToArray(); }
@if (selection?.Length > 0)
{

View File

@@ -17,7 +17,7 @@
- It uses a local method called Traverse() to select and display the markup and links.
*@
@{ var selection = Model?.Content.Root(); }
@{ var selection = Model?.Content.Root(PublishedContentCache, DocumentNavigationQueryService); }
<div class="sitemap">
@* Render the sitemap by passing the root node to the traverse method, below *@
@@ -26,13 +26,13 @@
@* Helper method to traverse through all descendants *@
@{
void Traverse(IPublishedContent? node)
void Traverse(IPublishedContent node)
{
//Update the level to reflect how deep you want the sitemap to go
const int maxLevelForSitemap = 4;
@* Select visible children *@
var selection = node?
var selection = node
.Children(VariationContextAccessor, PublishedContentCache, DocumentNavigationQueryService)
.Where(x => x.IsVisible(PublishedValueFallback) && x.Level <= maxLevelForSitemap)
.ToArray();

View File

@@ -927,7 +927,7 @@
/* This is your basic query to select the nodes you want */
var nodes = Model.Content.Children.Where(x => x.DocumentTypeAlias == "NewsArticle").OrderBy(x=>x.CreateDate);
var nodes = Model.Content.Children().Where(x => x.DocumentTypeAlias == "NewsArticle").OrderBy(x=>x.CreateDate);
int totalNodes = nodes.Count();
int totalPages = (int)Math.Ceiling((double)totalNodes / (double)pageSize);
@@ -1023,7 +1023,7 @@
<![CDATA[@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
@{
Layout = "SW_Master.cshtml";
var pages = Model.Content.Children.Where(x => x.IsVisible() && x.TemplateId > 0 && Umbraco.MemberHasAccess(x.Id, x.Path));
var pages = Model.Content.Children().Where(x => x.IsVisible() && x.TemplateId > 0 && Umbraco.MemberHasAccess(x.Id, x.Path));
}
<div id="mainContent" class="fc">
@@ -1347,7 +1347,7 @@
@helper traverse(IPublishedContent node)
{
var cc = node.Children.Where(x=>x.IsVisible() && x.TemplateId > 0);
var cc = node.Children().Where(x=>x.IsVisible() && x.TemplateId > 0);
if (cc.Count()>0)
{
<ul>