Closed (fixed)
Project:
Unicode Soft Hyphens
Version:
1.0.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
25 Feb 2026 at 15:14 UTC
Updated:
16 Mar 2026 at 22:50 UTC
Jump to comment: Most recent
This module supports ^10 || ^11. Drupal 11.1 introduced native Object-Oriented Hooks using PHP attributes. We want to adopt this modern pattern while maintaining support for Drupal 10 and 11.0.
Implement the "Shim" pattern recommended in Drupal 11.1 OO Hooks Change Record.
src/Hook/UnicodeSoftHyphensHooks.php.unicode_soft_hyphens_form_alter to UnicodeSoftHyphensHooks::formAlter.#[Hook('form_alter')] attribute on the method.unicode_soft_hyphens.services.yml with autowire: true (required for D10/11.0 to use it via service container, though D11.1+ discovers it automatically)..module (Legacy Shim):
unicode_soft_hyphens_form_alter() in the .module file.use Drupal\Core\Hook\Attribute\LegacyHook;.#[LegacyHook] attribute to the function. This tells Drupal 11.1+ to ignore this procedural function and use the OO Hook instead.// @phpstan-ignore-next-line
#[LegacyHook]
function unicode_soft_hyphens_form_alter(&$form, FormStateInterface $form_state, $form_id) {
\Drupal::service(UnicodeSoftHyphensHooks::class)->formAlter($form, $form_state, $form_id);
}
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
guido_sComment #3
guido_sComment #4
scontzen commentedComment #6
scontzen commentedConverted hook_form_alter() to OO hooks using the #[Hook] attribute.
Changes:
- Moved all logic from unicode_soft_hyphens.module into src/Hook/UnicodeSoftHyphensHooks.php
- Added #[LegacyHook] bridge in .module for backward compatibility with Drupal < 10.3
- Added unicode_soft_hyphens.services.yml to register the hook class
- Replaced global t() calls with $this->t() via StringTranslationTrait
- Fixed copy-paste error in docblock (node type builder comment said "block type config")
The procedural hook is kept as a #[LegacyHook] bridge so the module remains compatible with ^10 || ^11. Tested locally — config forms and soft hyphen button work as before.
Comment #7
guido_sI checked the code and tested it.
I added 1 commit to improve performance.
Seems to me you converted the hooks correctly but on testing I also noticed the feature isn't working in the layout builder as intended.
I know we had that working in a project, so I'm currently not sure if anything in core changed or in our module that broke the feature in layout builder. But as this is not related to this issue, I'll merge it and open a follow up issue to fix functionality in layout builder.
Comment #8
guido_sComment #11
guido_s