Substitute for old DocumentEvents.Copy.Before / After in XbyK?
I'm looking to port a Module over th XbyK from K13, and am looking for valid replacements for the above named Events. Do such things exist in XbyK?
A colleague pointed me to the CloneSettings.OnCloneInsert
API, and this is implemented easily enough in a Module. But, I was told this by the AI Assistant on the docs.kentico.com page:
Based on the available documentation, the CloneSettings.OnCloneInsert delegate in Xperience by Kentico is designed to handle actions before or after inserting a clone, allowing you to further modify the object according to your settings. This delegate provides hooks similar in spirit to the event-based approach in Kentico 13, but it is focused on the cloning process rather than document copy events specifically.
However, there is no explicit mention in the provided documentation that these callbacks are a direct or full replacement for the DocumentEvents.Copy.Before and DocumentEvents.Copy.After events. The new API is more focused on object cloning rather than document-specific copy events, and there may be differences in scope and behavior due to architectural changes in Xperience by Kentico.
So, I'm a little hesitant here now - the above seems logical (that the API is clone-centric and not really meant for copy), but I am unsure. Is this truly a valid replacement for the old(er) Copy events?
Thanks,
Chris
Environment
Xperience by Kentico version: [30.6.0]
.NET version: [8|9]
Execution environment: [SaaS|Private cloud (Azure/AWS/Virtual machine)]
Link to relevant Xperience by Kentico documentation
Answers
Aren't you looking for the global event handlers?
https://docs.kentico.com/documentation/developers-and-admins/customization/handle-global-events
It should be pretty much the same as in Kx13.
Hi Chyde,
We have an alternative option if you are using a specific object type, reference to this https://docs.kentico.com/documentation/developers-and-admins/customization/handle-global-events/handle-object-events
public class CustomObjectBeforeUpdateHandler : IInfoObjectEventHandler<InfoObjectBeforeUpdateEvent<CustomObjectTypeInfo>>
Agree with you Sean, Thanks for correcting me, here we have an reference to the handler https://api-reference.kentico.com/api/CMS.ContentEngine.ContentItemEventHandler-1.html and
Nikhila R
Nikhila,
If you want to check what public
APIs are available to developers you can use https://api-reference.kentico.com/api/CMS.html and perform a simple search.
General purpose AI chat experiences provided by frontier models, like ChatGPT or Gemini, might provide incorrect information when asking about Xperience by Kentico because they confuse Xperience by Kentico's API surface with Kentico Xperience 13 (and previous versions) or because they have some connection between APIs common in the ASP.NET Core space and Xperience.
If you check in the Xperience by Kentico API reference you can see that IContentItemEventsHandler
and IWebhookHandler
are not part of the public
API (they aren't even private
or internal
APIs 😅).
Additionally, you can ask the AI in our docs - https://docs.kentico.com/ - because it has up-to-date vector embeddings of the docs content and will be a lot more accurate with responses.
Thank you for the responses! Unfortunately, I'm still a little confused - here is the old K13 code I'm trying to transition:
DocumentEvents.Insert.Before += Document_Update_Before;
DocumentEvents.Update.Before += Document_Update_Before;
DocumentEvents.Copy.Before += Document_Copy_Before;
DocumentEvents.Copy.After += Document_Copy_After;
The first two lines I've (in XbyK) handled with this (I have a base handler so both are ultimately calling the same thing):
parameters.Services.AddInfoObjectEventHandler<InfoObjectBeforeUpdateEvent<ContentItemInfo>, UniqueIdentifierOnProductBeforeUpdateHandler>();
parameters.Services.AddInfoObjectEventHandler<InfoObjectBeforeInsertEvent<ContentItemInfo>, UniqueIdentifierOnProductBeforeInsertHandler>();
It's the last 2 lines above that I am unsure of - I see no Copy-related events exposed in the API. It seems in K13 there was a distinction between Insert/Update/Copy that I can't find in XbyK.
I've looked here: https://api-reference.kentico.com/api/CMS.ContentEngine.ContentItemEvents.html, and there is no Copy event listed, nor anything that seems to resemble it.
So, how do I implement what used to be a valid event in K13 that seems to no longer exist? Or - and this is 100% possible - am I missing something?
Chris,
Yeah, we don't have dedicated copy event APIs. Partially because cloning ("copying") is only possible with web pages and emails. There is no clone feature for Content hub items, yet. It's possible that we'll add clone events for all content items when cloning is available in the Content hub.
What prevents you from using the other content item lifecycle events? Is there something unique about your business logic that behaves differently for cloned items?
To answer this question, you have to login first.