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
170f329e
Commit
170f329e
authored
3 months ago
by
nicxvan
Browse files
Options
Downloads
Patches
Plain Diff
Rename hook to hook attribute and fix several variables
parent
2e8e7235
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/lib/Drupal/Core/Hook/HookCollectorPass.php
+22
-22
22 additions, 22 deletions
core/lib/Drupal/Core/Hook/HookCollectorPass.php
with
22 additions
and
22 deletions
core/lib/Drupal/Core/Hook/HookCollectorPass.php
+
22
−
22
View file @
170f329e
...
...
@@ -90,33 +90,33 @@ public function process(ContainerBuilder $container): array {
// These attributes need to be processed after all hooks have been
// processed.
$process
_a
fter
=
[
$process
A
fter
=
[
RemoveHook
::
class
=>
[],
ReOrderHook
::
class
=>
[],
];
foreach
(
array_keys
(
$container
->
getParameter
(
'container.modules'
))
as
$module
)
{
foreach
(
$collector
->
moduleHooks
[
$module
]
??
[]
as
$class
=>
$methods
)
{
foreach
(
$methods
as
$method
=>
$hooks
)
{
foreach
(
$hooks
as
$hook
)
{
assert
(
$hook
instanceof
HookOperation
);
if
(
isset
(
$process
_a
fter
[
get_class
(
$hook
)]))
{
$process
_a
fter
[
get_class
(
$hook
)][]
=
$hook
;
foreach
(
$hooks
as
$hook
Attribute
)
{
assert
(
$hook
Attribute
instanceof
HookOperation
);
if
(
isset
(
$process
A
fter
[
get_class
(
$hook
Attribute
)]))
{
$process
A
fter
[
get_class
(
$hook
Attribute
)][]
=
$hook
Attribute
;
continue
;
}
if
(
$class
!==
ProceduralCall
::
class
)
{
self
::
checkForProceduralOnlyHooks
(
$hook
,
$class
);
self
::
checkForProceduralOnlyHooks
(
$hook
Attribute
,
$class
);
}
// Set properties on hook class that are needed for registration.
$hook
->
set
(
$class
,
$module
,
$method
);
$hook
Attribute
->
set
(
$class
,
$module
,
$method
);
// Store a list of modules implementing hooks for simplifying
// registration and hook_module_implements_alter execution.
$legacyImplementationMap
[
$hook
->
hook
][
$hook
->
module
]
=
''
;
$legacyImplementationMap
[
$hook
Attribute
->
hook
][
$hook
Attribute
->
module
]
=
''
;
// Store the implementation details for registering the hook.
$implementations
[
$hook
->
hook
][
$hook
->
module
][
$class
][
$hook
->
method
]
=
$hook
->
method
;
$implementations
[
$hook
Attribute
->
hook
][
$hook
Attribute
->
module
][
$class
][
$hook
Attribute
->
method
]
=
$hook
Attribute
->
method
;
// Reverse lookup for modules implementing hooks.
$moduleFinder
[
$class
][
$hook
->
method
]
=
$hook
->
module
;
if
(
$hook
->
order
)
{
$hookOrderOperations
[]
=
$hook
;
$moduleFinder
[
$class
][
$hook
Attribute
->
method
]
=
$hook
Attribute
->
module
;
if
(
$hook
Attribute
->
order
)
{
$hookOrderOperations
[]
=
$hook
Attribute
;
}
}
}
...
...
@@ -127,7 +127,7 @@ public function process(ContainerBuilder $container): array {
// registering the hooks. This must happen after all collection, but before
// registration to ensure the hook it is removing has already been
// discovered.
foreach
(
$process
_a
fter
[
RemoveHook
::
class
]
as
$removeHook
)
{
foreach
(
$process
A
fter
[
RemoveHook
::
class
]
as
$removeHook
)
{
if
(
$module
=
(
$moduleFinder
[
$removeHook
->
class
][
$removeHook
->
method
]
??
''
))
{
unset
(
$legacyImplementationMap
[
$removeHook
->
hook
][
$module
]);
unset
(
$implementations
[
$removeHook
->
hook
][
$module
][
$removeHook
->
class
][
$removeHook
->
method
]);
...
...
@@ -138,7 +138,7 @@ public function process(ContainerBuilder $container): array {
// before registering the hooks. This must happen after all collection,
// but before registration to ensure this ordering directive takes
// precedence.
foreach
(
$process
_a
fter
[
ReOrderHook
::
class
]
as
$reOrderHook
)
{
foreach
(
$process
A
fter
[
ReOrderHook
::
class
]
as
$reOrderHook
)
{
$hookOrderOperations
[]
=
$reOrderHook
;
}
...
...
@@ -256,9 +256,9 @@ protected static function reOrderImplementations(ContainerBuilder $container, ar
// Collect classes and methods for
// self::registerComplexHookImplementations().
$classesAndMethods
=
$hookOrderOperation
->
order
->
classesAndMethods
;
foreach
(
$hookOrderOperation
->
order
->
modules
as
$module
s
)
{
foreach
(
$hookOrderOperation
->
order
->
modules
as
$module
)
{
foreach
(
$hooks
as
$hook
)
{
foreach
(
$implementations
[
$hook
][
$module
s
]
??
[]
as
$class
=>
$methods
)
{
foreach
(
$implementations
[
$hook
][
$module
]
??
[]
as
$class
=>
$methods
)
{
foreach
(
$methods
as
$method
)
{
$classesAndMethods
[]
=
[
$class
,
$method
];
$otherSpecifiers
[]
=
"
$class
::
$method
"
;
...
...
@@ -478,12 +478,12 @@ public function getImplementations($paths): array {
/**
* Checks for hooks which can't be supported in classes.
*
* @param \Drupal\Core\Hook\Attribute\Hook $hook
* @param \Drupal\Core\Hook\Attribute\Hook $hook
Attribute
* The hook to check.
* @param class-string $class
* The class the hook is implemented on.
*/
public
static
function
checkForProceduralOnlyHooks
(
Hook
$hook
,
string
$class
):
void
{
public
static
function
checkForProceduralOnlyHooks
(
Hook
$hook
Attribute
,
string
$class
):
void
{
$staticDenyHooks
=
[
'hook_info'
,
'install'
,
...
...
@@ -496,8 +496,8 @@ public static function checkForProceduralOnlyHooks(Hook $hook, string $class): v
'install_tasks_alter'
,
];
if
(
in_array
(
$hook
->
hook
,
$staticDenyHooks
)
||
preg_match
(
'/^(post_update_|preprocess_|update_\d+$)/'
,
$hook
->
hook
))
{
throw
new
\LogicException
(
"The hook
$hook->hook
on class
$class
does not support attributes and must remain procedural."
);
if
(
in_array
(
$hook
Attribute
->
hook
,
$staticDenyHooks
)
||
preg_match
(
'/^(post_update_|preprocess_|update_\d+$)/'
,
$hook
Attribute
->
hook
))
{
throw
new
\LogicException
(
"The hook
$hook
Attribute
->hook
on class
$class
does not support attributes and must remain procedural."
);
}
}
...
...
@@ -515,9 +515,9 @@ protected static function getAttributeInstances(\ReflectionClass $reflectionClas
$reflections
=
$reflectionClass
->
getMethods
(
\ReflectionMethod
::
IS_PUBLIC
);
$reflections
[]
=
$reflectionClass
;
foreach
(
$reflections
as
$reflection
)
{
if
(
$reflection
_a
ttributes
=
$reflection
->
getAttributes
(
HookOperation
::
class
,
\ReflectionAttribute
::
IS_INSTANCEOF
))
{
if
(
$reflection
A
ttributes
=
$reflection
->
getAttributes
(
HookOperation
::
class
,
\ReflectionAttribute
::
IS_INSTANCEOF
))
{
$method
=
$reflection
instanceof
\ReflectionMethod
?
$reflection
->
getName
()
:
'__invoke'
;
$attributes
[
$method
]
=
array_map
(
static
fn
(
\ReflectionAttribute
$ra
)
=>
$ra
->
newInstance
(),
$reflection
_a
ttributes
);
$attributes
[
$method
]
=
array_map
(
static
fn
(
\ReflectionAttribute
$ra
)
=>
$ra
->
newInstance
(),
$reflection
A
ttributes
);
}
}
return
$attributes
;
...
...
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