Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
2427e811
Commit
2427e811
authored
4 months ago
by
catch
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3482464
by nicxvan, berdir: Backport Hook and LegacyHook Attribute
(cherry picked from commit
5712beef
)
parent
899ed6f1
No related branches found
No related tags found
1 merge request
!10602
Issue #3438769 by vinmayiswamy, antonnavi, michelle, amateescu: Sub workspace does not clear
Pipeline
#362978
passed with warnings
4 months ago
Stage: 🪄 Lint
Stage: 🗜️ Test
Pipeline: drupal
#363020
Pipeline: drupal
#363005
Pipeline: drupal
#363001
+6
Changes
2
Pipelines
7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/lib/Drupal/Core/Hook/Attribute/Hook.php
+56
-0
56 additions, 0 deletions
core/lib/Drupal/Core/Hook/Attribute/Hook.php
core/lib/Drupal/Core/Hook/Attribute/LegacyHook.php
+17
-0
17 additions, 0 deletions
core/lib/Drupal/Core/Hook/Attribute/LegacyHook.php
with
73 additions
and
0 deletions
core/lib/Drupal/Core/Hook/Attribute/Hook.php
0 → 100644
+
56
−
0
View file @
2427e811
<?php
declare
(
strict_types
=
1
);
namespace
Drupal\Core\Hook\Attribute
;
/**
* 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.
*/
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
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
(
public
string
$hook
,
public
string
$method
=
''
,
public
?int
$priority
=
NULL
,
public
?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
;
}
}
This diff is collapsed.
Click to expand it.
core/lib/Drupal/Core/Hook/Attribute/LegacyHook.php
0 → 100644
+
17
−
0
View file @
2427e811
<?php
declare
(
strict_types
=
1
);
namespace
Drupal\Core\Hook\Attribute
;
/**
* 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.
*/
#[\Attribute(\Attribute::TARGET_FUNCTION)]
class
LegacyHook
{
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment