Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
documentation
Priority:
Normal
Category:
Bug report
Assigned:
Issue tags:
Reporter:
Created:
3 Jan 2015 at 21:56 UTC
Updated:
28 Jan 2015 at 08:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
jhodgdonWell, if you look at where the hook is invoked, actually what happens is:
a) hook_page_attachments() is called on each module that implements it. Starting with an empty array, the hook is invoked on each module, passing the result to the next module, to build up an array of attachments.
b) hook_page_attachments_alter() is then called on each module or theme that implements it. What is passed in is the result of hook_page_attachments().
c) If either of these hooks adds anything but #attached and #post_render_cache elements to the array, and exception is thrown.
So both of these hooks have incorrect documentation, and neither one mentions (c). The docs for both hooks need an update:
(1) Rather than $page they should call the parameter $attachments, and document that you should add elements to #attached and #post_render_cache elements only.
(2) In the alter hook docs, this sentence should be removed:
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.
This should be a good project for a novice contributor...
Comment #2
zealfire commentedThanks @jhodgdon for earlier helping me on irc.
Comment #3
jhodgdonThanks for the patch! It's a great start... A few things to address:
a) In both hooks:
I think we need to change the description here as well as the name of the parameter.
b) In both hooks:
I don't think we should use the word "attach" here for the array? How about "If you try to add anything..."?
The rest looks great!
Comment #4
zealfire commented@jhodgdon, modified patch as directed by you.Thanks
Comment #5
jhodgdonLooks good to me! I guess... Maybe in the _alter() hook, should we change the @param description to say:
Array of all attachments provided by hook_page_attachments() implementations.
?? Because it's an alter hook...
Comment #6
zealfire commented@jhodgdon,didn't noticed that earlier.Thanks
Comment #7
jhodgdonGreat, thanks!
Comment #8
catchShould this use @throws?
Comment #9
jhodgdonI don't think so. @throws is usually for "This function itself throws an exception", not for "If you put the wrong thing into your hook implementation, the function that invokes this hook will throw an exception", right?
Comment #10
jhodgdonProbably...
Comment #11
alexpottYep no @throws. Documentation is not frozen during beta. Committed 17c9a2a and pushed to 8.0.x. Thanks!