-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Cleanup IContentManager #16077
Merged
Merged
Cleanup IContentManager #16077
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
fe95666
Cleanup IContentManager
MikeAlhayek 93a0a4c
file-scope namespace
MikeAlhayek 383f69d
comment
MikeAlhayek f8edcfb
fix tests
MikeAlhayek 6c7f9b3
Merge branch 'main' into ma/remove-options-from-content-manager
hishamco 6152a8d
Merge branch 'main' into ma/remove-options-from-content-manager
MikeAlhayek 9471f62
Cleanup
MikeAlhayek 3e0580a
cleanup
MikeAlhayek 07592c1
Replace the latest paramter with VerionOption null
MikeAlhayek b419d64
Add support for all versions
MikeAlhayek 5b46118
toarray
MikeAlhayek b9be760
Update src/OrchardCore/OrchardCore.ContentManagement/DefaultContentMa…
MikeAlhayek cc0e4fa
Update src/OrchardCore/OrchardCore.ContentManagement/DefaultContentMa…
MikeAlhayek 4f32a89
Update extensions and the release notes
MikeAlhayek 4b5de4b
Merge branch 'ma/remove-options-from-content-manager' of https://gith…
MikeAlhayek 0e82d58
drop support for AllVersions option
MikeAlhayek 7a12e4b
update release notes
MikeAlhayek 0d11a6d
update comments
MikeAlhayek 5b95027
Fix the build
MikeAlhayek 9cef1a3
make the VersionOptions a record
MikeAlhayek 8351d62
Merge branch 'main' into ma/remove-options-from-content-manager
MikeAlhayek e6e9b98
record only with no struct
MikeAlhayek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= null
, why not the actual default value that is documented? I know this is what will be used internally but that would make more sense. If the other default changes for instance.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VersionOptions is a class. How can we provide a default value to the argument?