class Hook
Same name in other branches
- 11.x core/lib/Drupal/Core/Hook/Attribute/Hook.php \Drupal\Core\Hook\Attribute\Hook
This class will not have an effect until Drupal 11.1.0.
This class is included in earlier Drupal versions to prevent phpstan errors for modules implementing object oriented hooks using the #Hook and #LegacyHook attributes.
Hierarchy
- class \Drupal\Core\Hook\Attribute\Hook
Expanded class hierarchy of Hook
10 string references to 'Hook'
- drupal7.php in core/
modules/ migrate_drupal/ tests/ fixtures/ drupal7.php - A database agnostic dump for testing purposes.
- ModuleHandlerTest::testCachedGetImplementations in core/
tests/ Drupal/ Tests/ Core/ Extension/ ModuleHandlerTest.php - Tests getImplementations.
- ModuleHandlerTest::testCachedGetImplementationsMissingMethod in core/
tests/ Drupal/ Tests/ Core/ Extension/ ModuleHandlerTest.php - Tests getImplementations.
- ModuleHandlerTest::testGetHookInfo in core/
tests/ Drupal/ Tests/ Core/ Extension/ ModuleHandlerTest.php - Tests hook_hook_info() fetching through getHookInfo().
- ModuleHandlerTest::testHasImplementations in core/
tests/ Drupal/ Tests/ Core/ Extension/ ModuleHandlerTest.php - Tests hasImplementations.
File
-
core/
lib/ Drupal/ Core/ Hook/ Attribute/ Hook.php, line 14
Namespace
Drupal\Core\Hook\AttributeView source
class Hook {
/**
* Constructs a Hook attribute object.
*
* @param string $hook
* The short hook name, without the 'hook_' prefix.
* @param string $method
* (optional) The method name. If this attribute is on a method, this
* parameter is not required. If this attribute is on a class and this
* parameter is omitted, the class must have an __invoke() method, which is
* taken as the hook implementation.
* @param int|null $priority
* (optional) The priority of this implementation relative to other
* implementations of this hook. Hook implementations with higher priority
* are executed first. If omitted, the module order is used to order the
* hook implementations.
* @param string|null $module
* (optional) The module this implementation is for. This allows one module to
* implement a hook on behalf of another module. Defaults to the module the
* implementation is in.
*/
public function __construct(string $hook, string $method = '', ?int $priority = NULL, ?string $module = NULL) {
}
/**
* Set the method the hook should apply to.
*
* @param string $method
* The method that the hook attribute applies to.
* This only needs to be set when the attribute is on the class.
*/
public function setMethod(string $method) : static {
$this->method = $method;
return $this;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
Hook::setMethod | public | function | Set the method the hook should apply to. |
Hook::__construct | public | function | Constructs a Hook attribute object. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.