Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -140,6 +140,10 @@ public override async Task<IDisplayResult> UpdateAsync(BagPart part, UpdatePartE

await _contentHandlers.InvokeAsync((handler, context) => handler.UpdatingAsync(context), updateContentContext, _logger);

var cloneContentContext = new CloneContentContext(existingContentItem, contentItem);

await _contentHandlers.InvokeAsync((handler, context) => handler.CloningAsync(context), cloneContentContext, _logger);
Comment on lines +143 to +145
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we can do this, it seems to contradict what is commented above (IDs are expected to be kept).


contentItem.ContentItemId = model.ContentItems[i];
contentItem.Merge(existingContentItem);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Nodes;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Handlers;
using OrchardCore.ContentManagement.Routing;
using OrchardCore.Flows.Models;
Expand All @@ -7,6 +8,25 @@ 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 =>
Expand Down
2 changes: 2 additions & 0 deletions src/OrchardCore.Modules/OrchardCore.Flows/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace OrchardCore.Flows;

public sealed class Startup : StartupBase
{
public override int Order => -150;

public override void ConfigureServices(IServiceCollection services)
{
services.Configure<TemplateOptions>(o =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json.Nodes;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Handlers;
using OrchardCore.ContentManagement.Routing;
using OrchardCore.Taxonomies.Models;
Expand All @@ -7,6 +8,25 @@ namespace OrchardCore.Taxonomies.Handlers;

public class TaxonomyPartHandler : ContentPartHandler<TaxonomyPart>
{
private readonly IContentItemIdGenerator _idGenerator;

public TaxonomyPartHandler(IContentItemIdGenerator idGenerator) => _idGenerator = idGenerator;

public override Task CloningAsync(CloneContentContext context, TaxonomyPart part)
{
if (context.CloneContentItem.TryGet<TaxonomyPart>(out var clonedTaxonomyPart))
{
foreach (var termContentItem in clonedTaxonomyPart.Terms)
{
termContentItem.ContentItemId = _idGenerator.GenerateUniqueId(termContentItem);
}

clonedTaxonomyPart.Apply();
}

return Task.CompletedTask;
}

public override Task GetContentItemAspectAsync(ContentItemAspectContext context, TaxonomyPart part)
{
return context.ForAsync<ContainedContentItemsAspect>(aspect =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Handlers;
using OrchardCore.Widgets.Models;

namespace OrchardCore.Widgets.Handlers;

public class WidgetsListPartHandler : ContentPartHandler<WidgetsListPart>
{
private readonly IContentItemIdGenerator _idGenerator;

public WidgetsListPartHandler(IContentItemIdGenerator idGenerator) => _idGenerator = idGenerator;

public override Task CloningAsync(CloneContentContext context, WidgetsListPart part)
{
if (context.CloneContentItem.TryGet<WidgetsListPart>(out var clonedWidgetsListPart))
{
foreach (var zone in part.Widgets.Keys)
{
foreach (var widgetContentItem in part.Widgets[zone])
{
widgetContentItem.ContentItemId = _idGenerator.GenerateUniqueId(widgetContentItem);
}
}

clonedWidgetsListPart.Apply();
}

return Task.CompletedTask;
}
}
4 changes: 3 additions & 1 deletion src/OrchardCore.Modules/OrchardCore.Widgets/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using OrchardCore.DisplayManagement;
using OrchardCore.Modules;
using OrchardCore.Widgets.Drivers;
using OrchardCore.Widgets.Handlers;
using OrchardCore.Widgets.Models;
using OrchardCore.Widgets.Services;
using OrchardCore.Widgets.Settings;
Expand All @@ -20,7 +21,8 @@ public override void ConfigureServices(IServiceCollection services)
services.AddShapeTableProvider<ContentCardShapes>();
// Widgets List Part
services.AddContentPart<WidgetsListPart>()
.UseDisplayDriver<WidgetsListPartDisplayDriver>();
.UseDisplayDriver<WidgetsListPartDisplayDriver>()
.AddHandler<WidgetsListPartHandler>();

services.AddScoped<IStereotypesProvider, WidgetStereotypesProvider>();

Expand Down
Loading