-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--------- Co-authored-by: Hisham Bin Ateya <hishamco_2007@yahoo.com> Co-authored-by: Zoltán Lehóczky <zoltan.lehoczky@lombiq.com>
- Loading branch information
1 parent
58149c4
commit 77c69c6
Showing
15 changed files
with
291 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/OrchardCore.Modules/OrchardCore.ContentFields/Views/ContentPickerField.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/OrchardCore/OrchardCore.ContentManagement.Abstractions/ContentManagerExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text.Json.Nodes; | ||
using System.Threading.Tasks; | ||
using OrchardCore.ContentManagement.Handlers; | ||
|
||
namespace OrchardCore.ContentManagement; | ||
|
||
public static class ContentManagerExtensions | ||
{ | ||
public static Task<TAspect> PopulateAspectAsync<TAspect>(this IContentManager contentManager, IContent content) where TAspect : new() | ||
{ | ||
return contentManager.PopulateAspectAsync(content, new TAspect()); | ||
} | ||
|
||
public static async Task<bool> HasPublishedVersionAsync(this IContentManager contentManager, IContent content) | ||
{ | ||
if (content?.ContentItem == null) | ||
{ | ||
return false; | ||
} | ||
|
||
return content.ContentItem.IsPublished() || | ||
(await contentManager.GetAsync(content.ContentItem.ContentItemId, VersionOptions.Published) != null); | ||
} | ||
|
||
public static Task<ContentItemMetadata> GetContentItemMetadataAsync(this IContentManager contentManager, IContent content) | ||
{ | ||
return contentManager.PopulateAspectAsync<ContentItemMetadata>(content); | ||
} | ||
|
||
public static async Task<IEnumerable<ContentItem>> LoadAsync(this IContentManager contentManager, IEnumerable<ContentItem> contentItems) | ||
{ | ||
ArgumentNullException.ThrowIfNull(contentItems); | ||
|
||
var results = new List<ContentItem>(contentItems.Count()); | ||
|
||
foreach (var contentItem in contentItems) | ||
{ | ||
results.Add(await contentManager.LoadAsync(contentItem)); | ||
} | ||
|
||
return results; | ||
} | ||
|
||
public static async IAsyncEnumerable<ContentItem> LoadAsync(this IContentManager contentManager, IAsyncEnumerable<ContentItem> contentItems) | ||
{ | ||
ArgumentNullException.ThrowIfNull(contentItems); | ||
|
||
await foreach (var contentItem in contentItems) | ||
{ | ||
yield return await contentManager.LoadAsync(contentItem); | ||
} | ||
} | ||
|
||
public static async Task<ContentValidateResult> UpdateValidateAndCreateAsync(this IContentManager contentManager, ContentItem contentItem, VersionOptions options) | ||
{ | ||
await contentManager.UpdateAsync(contentItem); | ||
var result = await contentManager.ValidateAsync(contentItem); | ||
|
||
if (result.Succeeded) | ||
{ | ||
await contentManager.CreateAsync(contentItem, options); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/// <summary> | ||
/// Gets either the container content item with the specified id and version, or if the json path supplied gets the contained content item. | ||
/// </summary> | ||
/// <param name="contentManager">The <see cref="IContentManager"/> instance.</param> | ||
/// <param name="contentItemId">The id content item id to load.</param> | ||
/// <param name="options">The version option.</param> | ||
/// <param name="jsonPath">The json path of the contained content item.</param> | ||
public static async Task<ContentItem> GetAsync(this IContentManager contentManager, string contentItemId, string jsonPath, VersionOptions options = null) | ||
{ | ||
var contentItem = await contentManager.GetAsync(contentItemId, options); | ||
|
||
// It represents a contained content item. | ||
if (!string.IsNullOrEmpty(jsonPath)) | ||
{ | ||
var root = (JsonObject)contentItem.Content; | ||
contentItem = root.SelectNode(jsonPath)?.ToObject<ContentItem>(); | ||
|
||
return contentItem; | ||
} | ||
|
||
return contentItem; | ||
} | ||
} |
Oops, something went wrong.