function HookCollectorPass::checkForProceduralOnlyHooks

Checks for hooks which can't be supported in classes.

Parameters

\Drupal\Core\Hook\Attribute\Hook $hook: The hook to check.

string $class: The class the hook is implemented on.

Return value

void

1 call to HookCollectorPass::checkForProceduralOnlyHooks()
HookCollectorPass::getHookAttributesInClass in core/lib/Drupal/Core/Hook/HookCollectorPass.php
An array of Hook attributes on this class with $method set.

File

core/lib/Drupal/Core/Hook/HookCollectorPass.php, line 362

Class

HookCollectorPass
Collects and registers hook implementations.

Namespace

Drupal\Core\Hook

Code

public static function checkForProceduralOnlyHooks(Hook $hook, string $class) : void {
    $staticDenyHooks = [
        'cache_flush',
        'hook_info',
        'install',
        'module_implements_alter',
        'module_preinstall',
        'module_preuninstall',
        'modules_installed',
        'modules_uninstalled',
        'requirements',
        'schema',
        'uninstall',
        'update_last_removed',
    ];
    if (in_array($hook->hook, $staticDenyHooks) || preg_match('/^(post_update_|preprocess_|process_|update_\\d+$)/', $hook->hook)) {
        throw new \LogicException("The hook {$hook->hook} on class {$class} does not support attributes and must remain procedural.");
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.