Problem/Motivation
The "Insert soft hyphen" button does not appear when configuring custom blocks within Layout Builder (e.g., via "Add Block" or "Configure" actions).
The module currently relies on ContentEntityFormInterface to detect entity forms. However, Layout Builder forms (layout_builder_configure_block) do not implement this interface directly; they wrap the entity form within a settings array. As a result, the check at the beginning of formAlter() causes the logic to exit prematurely for Layout Builder contexts.
Additionally, even if the check is bypassed, the logic for retrieving the block entity instance and placing the button needs to be adapted for the Layout Builder form structure, which nests the block entity form inside $form['settings']['block_form'].
There are also potential issues with the JavaScript focus tracking (soft-hyphen.js) failing to attach correctly to elements loaded via Drupal's AJAX/Off-canvas dialogs in Layout Builder.
Steps to reproduce
- Enable the Unicode Soft Hyphens module.
- Create or edit a Custom Block Type (e.g., "Basic Block") and enable the "Soft Hyphen" setting in its edit form.
- Enable Layout Builder on a Content Type (e.g., "Article").
- Go to "Manage Layout" for an article.
- Click "Add Block" and select "Create custom block" -> "Basic Block".
- Observation: The "Insert soft hyphen" button is missing from the block configuration form.
Proposed resolution
- Update
hook_form_alterimplementation to explicitly supportlayout_builder_configure_blockbase form IDs. - Remove or modify the strict
ContentEntityFormInterfacecheck to allow Layout Builder forms. - Update logic to correctly retrieve the block entity from
$form['settings']['block_form']['#block']or['#entity']in Layout Builder contexts. - Ensure the button is inserted into the correct part of the render array (e.g.,
$form['settings']) so it is visible in the off-canvas dialog. - Refactor
soft-hyphen.jsto ensure focus listeners are attached to dynamically loaded form elements (AJAX) and correctly track the active input field globally.
Remaining tasks
- Create a patch implementing Layout Builder support.
- Test with standard Block Layout and Layout Builder configurations.
Issue fork unicode_soft_hyphens-3576651
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
scontzen commentedComment #4
scontzen commentedFixed all points from the issue summary. PHP: two branches for form detection, button placed in
$form['settings']with weights for correct positioning. JS: focus listener ininitField()for AJAX context, alert made translatable. CSS:#drupal-off-canvas .sh-btnfor off-canvas styling. Node/block form behavior unchanged.Tested on Drupal 11, PHP 8.4, Olivero + Gin.
Comment #5
scontzen commented