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)

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

hitchshock created an issue. See original summary.

hitchshock’s picture

Title: Drupal 11 upgrade path » Drupal 11 upgrade path for hooks

nickolaj made their first commit to this issue’s fork.

nickolaj’s picture

Status: Active » Needs review

Migrated 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.

hitchshock’s picture

Status: Needs review » Fixed

@nickolaj Thanks!
It works well. merged into the dev branch. It will be released soon.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • hitchshock committed 3414a8d2 on 1.0.x authored by nickolaj
    Issue #3573436: Migrated procedural hooks to OOP Hook attribute cl...
    

ibis made their first commit to this issue’s fork.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.