Problem/Motivation
Drupal 11 switched from the hooks in the *.module file to \Drupal\Core\Hook\Attribute\Hook attribute.
In the new release, we are planning to make the module requirement drupal/core >= 10.3, so, at least we need to prepare the future hook class. So, in the future, when the module requirement will be drupal/core => 11.1 we can easily switch to the hook attribute and just remove the module file.
Proposed resolution
- first see a doc on how to make this migration correctly, to support D11 and D10 at the same time
https://www.drupal.org/node/3442349
- Make src/Hook/FormHooks and move the code of pdf_to_imagefield_form_alter there
- Make src/Hook/EntityHooks and move the code of pdf_to_imagefield_convert_pdf there
- in the module file use \Drupal::classResolver() to call the moved code from the expected classes
- Remember that the hook_entity_insert of the module must be handled after all other same hooks (according to pdf_to_imagefield_module_implements_alter). This means that the hook attribute must have the order parameter (Order::Last)
Issue fork pdf_to_imagefield-3573436
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
hitchshockComment #5
nickolajMigrated procedural hooks to OOP Hook attribute classes (`FormHooks`, `EntityHooks`) with `#[LegacyHook]` bridging for Drupal 10.3 compatibility and `Order::Last` on entity hooks to preserve execution order.
Comment #6
hitchshock@nickolaj Thanks!
It works well. merged into the dev branch. It will be released soon.