-
Hi everyone, I'm trying to understand if there's the possibility of using an event handler to intercept when a Content Item, created in the backoffice, is saved by the admin. I know there's the possibility to use I need to intercept the saving of a I imagine something like this: using OrchardCore.ContentManagement.Handlers;
using OrchardCore.ContentManagement;
using System.Threading.Tasks;
public class CustomContentItemHandler : ContentHandler
{
public override async Task UpdatingAsync(UpdateContentContext context)
{
var contentItem = context.ContentItem;
// Intercept Book Content Item
if (contentItem.ContentType == "Book")
{
// Retrieve here the "Bag" part contained in it, and perform checks
}
await base.UpdatingAsync(context);
}
}
Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
You are looking for |
Beta Was this translation helpful? Give feedback.
I think I missed your second question. Yes you can have event handlers on existing parts such as
BagPart
. Just do the same thing you would for a custom partpublic class MyBagPartHandler : ContentPartHandler<BagPart>
and then in the startupservices.AddContentPart<BagPart>().AddHandler<MyBagPartHandler>();
. It may seem odd to be callingAddContentPart
on a Part that has already been added, but if you look, this method callsGetOrAddContentPart
, so you are not adding it twice.Now that I think I understand what you are trying to do, this is probably the best approach and you can ignore the workflow idea. ContentPartHandlers can get the content item easily enough, so for some reason if you …