Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add object oriented hook implementations #194

Open
rodrigoaguilera opened this issue Nov 19, 2024 · 5 comments
Open

Add object oriented hook implementations #194

rodrigoaguilera opened this issue Nov 19, 2024 · 5 comments

Comments

@rodrigoaguilera
Copy link

Drupal >11.1.0 has support for hook implementations in classes with attributes.
https://www.drupal.org/node/3442349

And it seems that many core hooks are moving to this kind of implementation.

Is there any interest in implementing this early to generate code?

@andypost
Copy link
Contributor

Sounds like good idea

@Chi-teck
Copy link
Owner

I propose generating single hook classes like following.

#[Hook('help')]
final readonly class Help {

  /**
   * Implements hook_help().
   */
  public function __invoke(): void {
  
  }

}

@weitzman
Copy link
Contributor

Nice ... I propose omitting the Implements hook_help(). doxygen. I know that core kept it so far but thats because they couldn't quickly agree on how to deal with api module integration. This isn't a concern for custom drupal code. I think Drupal core will eventually get rid of this duplicative code comment.

@Chi-teck
Copy link
Owner

The relevant core issue
https://www.drupal.org/project/drupal/issues/3493453

@PierrePaul
Copy link
Contributor

Some static code analysis tools might whine a bit about a function with no doc comment though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants