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

Fix an exception in ListPart with header #14473

Merged
merged 3 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -123,11 +122,11 @@ private IDisplayResult BuildViewModel(string containerId, string containerConten

if (settings != null)
{
// Add list part navigation
// Add list part navigation.
results.Add(Initialize<ListPartNavigationAdminViewModel>("ListPartNavigationAdmin", async model =>
{
model.ContainedContentTypeDefinitions = GetContainedContentTypes(settings).ToArray();
model.Container = await _contentManager.GetAsync(containerId, VersionOptions.Latest);
model.Container = await GetContainerAsync(containerId);
model.EnableOrdering = settings.EnableOrdering;
model.ContainerContentTypeDefinition = definition;
}).Location("Content:1.5"));
Expand All @@ -144,30 +143,26 @@ private IDisplayResult BuildViewModel(string containerId, string containerConten
}

private IDisplayResult GetListPartHeader(string containerId, ListPartSettings listPartSettings)
{
return Initialize<ListPartHeaderAdminViewModel>("ListPartHeaderAdmin", async model =>
=> Initialize<ListPartHeaderAdminViewModel>("ListPartHeaderAdmin", async model =>
{
var container = await _contentManager.GetAsync(containerId);

if (container == null)
{
return;
}

model.ContainerContentItem = container;
model.ContainerContentItem = await GetContainerAsync(containerId);

if (listPartSettings != null)
{
model.ContainedContentTypeDefinitions = GetContainedContentTypes(listPartSettings).ToArray();
model.EnableOrdering = listPartSettings.EnableOrdering;
}
}).Location("Content:1");
}

private IEnumerable<ContentTypeDefinition> GetContainedContentTypes(ListPartSettings settings) =>
settings.ContainedContentTypes
?.Select(contentType => _contentDefinitionManager.GetTypeDefinition(contentType))
.Where(definition => definition is not null)
?? Enumerable.Empty<ContentTypeDefinition>();
// Initially, attempt to locate a published container.
// If none is found, try acquiring the most recent unpublished version.
private async Task<ContentItem> GetContainerAsync(string containerId)
=> await _contentManager.GetAsync(containerId) ?? await _contentManager.GetAsync(containerId, VersionOptions.Latest);

private IEnumerable<ContentTypeDefinition> GetContainedContentTypes(ListPartSettings settings)
=> settings.ContainedContentTypes
?.Select(contentType => _contentDefinitionManager.GetTypeDefinition(contentType))
.Where(definition => definition is not null)
?? Enumerable.Empty<ContentTypeDefinition>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
@inject OrchardCore.ContentManagement.Display.IContentItemDisplayManager ContentItemDisplayManager
@inject OrchardCore.DisplayManagement.ModelBinding.IUpdateModelAccessor UpdateModelAccessor

@if (Model.ContainerContentItem == null)
MikeAlhayek marked this conversation as resolved.
Show resolved Hide resolved
{
return;
}

<div class="card text-bg-theme mb-3">
<div class="card-body">
@await DisplayAsync(await ContentItemDisplayManager.BuildDisplayAsync(Model.ContainerContentItem, UpdateModelAccessor.ModelUpdater, "HeaderAdmin"))
Expand Down