Problem/Motivation
The mercury_editor_content_lock module currently hardcodes its hook_form_FORM_ID_alter() implementation to work only with the Page content type:
function mercury_editor_content_lock_form_node_page_mercury_editor_form_alter() { ... }
As a result, nodes of other content types using the Mercury Editor do not benefit from content locking.
Steps to reproduce
- Enable the Mercury Editor and Content Lock modules.
- Assign a different content type (e.g., Article) to use the Mercury Editor.
- Attempt to edit this node while another user also has it open.
- No content lock is triggered or enforced for non-Page types.
Proposed resolution
Generalise the hook_form_FORM_ID_alter() to apply to all node types that use the Mercury Editor, rather than just the hardcoded node_page_mercury_editor_form.
For example, use:
function mercury_editor_content_lock_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if (!str_starts_with($form_id, 'node_') || !str_ends_with($form_id, '_mercury_editor_form')) {
return;
}
// Rest of mercury_editor_content_lock_form_node_page_mercury_editor_form_alter() function.
}
or leverage the `mercury_editor.context` service to confirm the form is in the editor context:
function mercury_editor_content_lock_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$context = \Drupal::service('mercury_editor.context');
if (!$context->isEditor()) {
return;
}
// Rest of mercury_editor_content_lock_form_node_page_mercury_editor_form_alter() function.
}
Side note / related discovery:
When calling `mercury_editor_content_lock_form_node_page_mercury_editor_form_alter() `programmatically from a custom module for non-Page content types, the lock modal appears. However, this modal does not show when using the original hardcoded form alter on Page content types, suggesting a potential secondary bug or inconsistency.