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

  1. Enable the Unicode Soft Hyphens module.
  2. Create or edit a Custom Block Type (e.g., "Basic Block") and enable the "Soft Hyphen" setting in its edit form.
  3. Enable Layout Builder on a Content Type (e.g., "Article").
  4. Go to "Manage Layout" for an article.
  5. Click "Add Block" and select "Create custom block" -> "Basic Block".
  6. Observation: The "Insert soft hyphen" button is missing from the block configuration form.

Proposed resolution

  • Update hook_form_alter implementation to explicitly support layout_builder_configure_block base form IDs.
  • Remove or modify the strict ContentEntityFormInterface check 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.js to 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.
Command icon 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

guido_s created an issue. See original summary.

scontzen’s picture

Assigned: Unassigned » scontzen

scontzen’s picture

Status: Active » Needs review

Fixed 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 in initField() for AJAX context, alert made translatable. CSS: #drupal-off-canvas .sh-btn for off-canvas styling. Node/block form behavior unchanged.

Tested on Drupal 11, PHP 8.4, Olivero + Gin.

scontzen’s picture

Assigned: scontzen » guido_s