Description:
- Create a class in the Drupal\modulename\Hook namespace (or subdirectory). This will be automatically registered as an autowired service.
- Use the new
Drupal\Core\Hook\Attribute\Hookattribute either on methods or on the class. If it is on the class and the class doesn't have an__invokemethod then amethodargument is required.
https://www.drupal.org/node/3442349
node.module
use Drupal\Core\Hook\Attribute\LegacyHook;
use Drupal\node\Hook\NodeHooks;
// @phpstan-ignore-next-line
#[LegacyHook]
function node_user_cancel($edit, UserInterface $account, $method) {
// This only needs to be returned if the hook previously had a return.
return \Drupal::service(NodeHooks::class)->userCancel($edit, $account, $method);
}