Skip to content

Provide rules to bring type inspection to hooks #918

@mglaman

Description

@mglaman

Feature request

Hooks are not typed and we have no way of knowing what hooks are available in the system, since hooks are not defined and only arbitrarily invoked.

We can't just scan *.api.php files as we tried this and it randomly broke on contrib code. In fact in DeprecatedHookImplementation we hardcode two specific hooks.

I think the solution is to build specific rules for known hooks. Maybe it can be made scalable, but I'd like to start with a rule per-hook until we find repeatable patterns.

Initial idea

Rules\Hooks\FormAlterRule (OOP, target class method nodes) and Rules\Hooks\ProceduralFormAlterRule (function, target function definition

Find things matching hook_form_alter and friends by base ID, etc. Verify the arguments and order of array, FormStateInterface, string. Not all are required to exist.

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions