To achieve synchronization of the checkbox across different language versions of a custom page type in Kentico, you are on the right track by using global event handlers. However, it appears you may not be capturing the right event when the checkbox is updated in the 'Form' tab.
Key Considerations:
DocumentEvents vs. ObjectEvents: The DocumentEvents.Update.Before event should generally capture updates to documents (including changes made through the Form tab). However, ensure that the checkbox is tied to the document's data and is being recognized as an update to the document.
Debugging Event Triggers: Since you confirmed that ObjectEvents.Update.Before is firing but DocumentEvents.Update.Before is not, ensure that the event is correctly associated with the document being edited. Sometimes, the user interface may trigger a different update than expected.
Form Tab Interactions: If your checkbox is part of a custom form, make sure that it is properly bound to the document properties. Sometimes, issues arise if the property isn't configured correctly, leading to the event not firing.
Steps to Troubleshoot:
Check the Checkbox Binding: Ensure that the checkbox is mapped to a property of the document in the form configuration. This is essential for triggering the DocumentEvents.Update events.
Utilize Debugging: Confirm that the LanguageToggleSyncBeforeUpdateHandler is indeed receiving the expected document object. You can place breakpoints or log outputs to verify the document type and its properties during the event.
Review Module Registration: Ensure that your module is correctly registered and that the event handlers are indeed being invoked at the right point in the document lifecycle.
Synchronizing Language Versions:
To synchronize the checkbox across language versions, you can fetch the related document versions based on the current document's culture. Here’s a snippet to get you started:
csharp
Copy code
private void LanguageToggleSyncBeforeUpdateHandler(object sender, DocumentEventArgs e)
{
if (e.Node != null && e.Node.NodeClassName == "custom.AgencyOffice")
{
// Get the current checkbox value
bool checkboxValue = e.Node.GetBooleanValue("YourCheckboxFieldName");
// Get all language versions of the document
var relatedDocuments = DocumentHelper.GetDocuments()
.WhereEquals("NodeClassName", "custom.AgencyOffice")
.WhereEquals("NodeParentID", e.Node.NodeParentID)
.ToList();
foreach (var relatedDocument in relatedDocuments)
{
if (relatedDocument.NodeID != e.Node.NodeID)
{
// Synchronize the checkbox value
relatedDocument.SetValue("YourCheckboxFieldName", checkboxValue);
relatedDocument.Update();
}
}
}
}
Summary:
Ensure your checkbox is properly bound to the document properties.
Confirm that the right events are firing during the update process.
Implement the synchronization logic as outlined above to update related language versions.
By refining your approach based on these points, you should be able to achieve the desired synchronization across your custom page type's language versions.