-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathBagPartHandler.cs
More file actions
44 lines (36 loc) · 1.43 KB
/
BagPartHandler.cs
File metadata and controls
44 lines (36 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using System.Text.Json.Nodes;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Handlers;
using OrchardCore.ContentManagement.Routing;
using OrchardCore.Flows.Models;
namespace OrchardCore.Flows.Handlers;
public class BagPartHandler : ContentPartHandler<BagPart>
{
private readonly IContentItemIdGenerator _idGenerator;
public BagPartHandler(IContentItemIdGenerator idGenerator) => _idGenerator = idGenerator;
public override Task CloningAsync(CloneContentContext context, BagPart part)
{
if (context.CloneContentItem.TryGet<BagPart>(out var clonedBagPart))
{
foreach (var contentItem in clonedBagPart.ContentItems)
{
contentItem.ContentItemId = _idGenerator.GenerateUniqueId(contentItem);
}
clonedBagPart.Apply();
}
return Task.CompletedTask;
}
public override Task GetContentItemAspectAsync(ContentItemAspectContext context, BagPart part)
{
return context.ForAsync<ContainedContentItemsAspect>(aspect =>
{
aspect.Accessors.Add((jsonObject) =>
{
// Content.Path contains the accessor for named bag parts and typed bag parts.
var jContent = (JsonObject)part.Content;
return jsonObject[jContent.GetNormalizedPath()]["ContentItems"] as JsonArray;
});
return Task.CompletedTask;
});
}
}