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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
17c9a2a0
Commit
17c9a2a0
authored
Jan 14, 2015
by
Alex Pott
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2401355
by zealfire: hook_page_attachments() and _alter() hooks have incorrect docs
parent
b8f63edd
No related branches found
No related tags found
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/modules/system/theme.api.php
+16
-14
16 additions, 14 deletions
core/modules/system/theme.api.php
with
16 additions
and
14 deletions
core/modules/system/theme.api.php
+
16
−
14
View file @
17c9a2a0
...
...
@@ -874,18 +874,21 @@ function hook_css_alter(&$css) {
* depends on the elements of other modules, use hook_page_attachments_alter()
* instead, which runs after this hook.
*
* @param array &$page
* An empty renderable array representing the page.
* If you try to add anything but #attached and #post_render_cache to the array
* an exception is thrown.
*
* @param array &$attachments
* An array that you can add attachments to.
*
* @see hook_page_attachments_alter()
*/
function
hook_page_attachments
(
array
&
$
page
)
{
function
hook_page_attachments
(
array
&
$
attachments
)
{
// Unconditionally attach an asset to the page.
$
page
[
'#attached'
][
'library'
][]
=
'core/domready'
;
$
attachments
[
'#attached'
][
'library'
][]
=
'core/domready'
;
// Conditionally attach an asset to the page.
if
(
!
\Drupal
::
currentUser
()
->
hasPermission
(
'may pet kittens'
))
{
$
page
[
'#attached'
][
'library'
][]
=
'core/jquery'
;
$
attachments
[
'#attached'
][
'library'
][]
=
'core/jquery'
;
}
}
...
...
@@ -896,20 +899,19 @@ function hook_page_attachments(array &$page) {
* add attachments to the page that depend on another module's attachments (this
* hook runs after hook_page_attachments().
*
* If you want to alter the attachments added by other modules or if your module
* depends on the elements of other modules, use hook_page_attachments_alter()
* instead, which runs after this hook.
* If you try to add anything but #attached and #post_render_cache to the array
* an exception is thrown.
*
* @param array &$
page
* A
n empty renderable array representing the page
.
* @param array &$
attachments
* A
rray of all attachments provided by hook_page_attachments() implementations
.
*
* @see hook_page_attachments_alter()
*/
function
hook_page_attachments_alter
(
array
&
$
page
)
{
function
hook_page_attachments_alter
(
array
&
$
attachments
)
{
// Conditionally remove an asset.
if
(
in_array
(
'core/jquery'
,
$
page
[
'#attached'
][
'library'
]))
{
$index
=
array_search
(
'core/jquery'
,
$
page
[
'#attached'
][
'library'
]);
unset
(
$
page
[
'#attached'
][
'library'
][
$index
]);
if
(
in_array
(
'core/jquery'
,
$
attachments
[
'#attached'
][
'library'
]))
{
$index
=
array_search
(
'core/jquery'
,
$
attachments
[
'#attached'
][
'library'
]);
unset
(
$
attachments
[
'#attached'
][
'library'
][
$index
]);
}
}
...
...
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