Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
base system
Priority:
Critical
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
5 Oct 2014 at 16:12 UTC
Updated:
13 Nov 2014 at 07:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
catchComment #2
dawehnerThis certainly can first be started once we have moved the block rendering process out of
hook_page_builder()Comment #3
wim leersHaving looked at this, we can only remove the block rendering process out of
hook_page_build()in #2352155, see #2352155-4: Remove HtmlFragment/HtmlPage for related issues that explain why. In short: we've been working towards moving the block building intoDefaultHtmlFragmentRenderer, and since that will go away, we also need to re-evaluate where block building should go in that context (block building is a specific page variant, so: "re-evaluate where instantiating a specific page variant should go" is the actual question).But we already know we want to remove the concept of
hook_page_build(), which allows any module to inject any random crap in any region, so we can already move forward with this, or at the very least begin the review process. This is the most contentious bit, and I've highlighted it ininterdiff-contentious.txt.Comment #5
wim leersComment #6
wim leersNoteworthy things that we must tackle in this issue/patch:
block.installthat alteredblockmodule's weight, specifically to allow other modules to alter its block inhook_page_alter()! Incredible, right?! I removed that.page_topandpage_bottom"internal regions" is broken in HEAD, but is only exposed in this patch. This regression was also introduced by #2068471: Normalize Controller/View-listener behavior with a Page object.hook_page_alter()is used to wrap each region in theregion"theme wrapper"!theme.api.phphas been updated to explain when themes should implementhook_page_attachments_alter().MainContentFallbackTesthas become nonsensical/irrelevant: it used to test duplicating the main content to another region, but that is no longer allowed byhook_page_build(). So: removed that test case and documented the existing ones, we still have full test coverage.Comment #7
catchCould we just call that $attachments? For implementors of this hook, it won't be a fake page any more, just an empty array and they're only adding elements to the top level.
Can't use ModuleHandler::invokeAll()? If it's a merging issue could use a comment, but looks like artifact from original code.
General questions:
1. In Drupal 7 you had to add attachments to a region within the overall page array so $page['footer']['#attached'] - this is an unfixed bug in 7.x as far as I know, do we want to do do the empty array trick in system_page_attachments() then drupal_render_collect_attached() on the resulting array, or are we saying that all 8.x modules already add assets top level. Fine with either answer, it's simpler in the patch but it'd fail silently for an unported 7.x module.
2. The workaround for _block_page_build() I can probably live with to unblock other work, we could use a new critical to put that somewhere though. Looks to me like half of block_page_build() shouldn't be in there, and the other half is one or two lines.
Comment #8
wim leersBut the implementations of
hook_page_attachments()operate by setting$page['#attached']['library'][] = 'mymodule/library';— hence$attachments would be weird. Unless you're saying only the code <em>invoking</em> <code>hook_page_attachments()should use this$attachmentsvariable name?I'd love that, but AFAICT that doesn't support passing arguments by reference, which this needs.
_block_page_build(): I agree, that's why I have a@todoin there to fix it in #2352155: Remove HtmlFragment/HtmlPage. Isn't that sufficient?Comment #9
catchYes just the code invoking.
Does it still work after this patch though? We're only taking attachments out of $page['#attachments'], so if I add something to $page['foo']['#attachments'] I'd expect that to be ignored.
Here we only get things out of the top level. That's fine for the invoker of hook_page_attachments(), but I'm not sure if system_page_build() should handle nested arrays.
If #2352155: Remove HtmlFragment/HtmlPage is the issue for _block_page_build() that's great.
Comment #10
wim leersDone.
Oh! I thought you were referring to
$page['<region>']['#attached']already being set, but you were referring to it being set inhook_page_build()! Hence you're right.You said . So you either want to see it be supported, or get an explicit failure. Makes sense.
I think explicit failure is better here, because it allows us to also explicitly fail if you're adding new render arrays in
hook_page_build(), which we don't support anymore, and hence would also be silent failures (and developers will be wondering — not good!).Done.
Comment #11
catchHaven't done another line by line review yet but this looks good to me now.
Comment #12
moshe weitzman commentedCode looks good to me. One significant bit of feedback and a couple nits:
throw new \LogicException('Only #attached and #post_render_cache may be set in hook_page_attachments_alter()');. Missing period.+ // and, for backwards compatibility.missing the word: themesComment #13
catch@Moshe answered on the BC layer here:
#2350615-21: [policy, no patch] What changes can be accepted during the Drupal 8 beta phase?
Comment #14
wim leersRTBC per #11 and #12, since #12 only required nitpicks to be fixed.
Even if we decide to remove
hook_page_build()andhook_page_alter(), that decision doesn't need to hold up this issue; that can be done in a non-critical follow-up. Moshe agreed with this.Change record created.
Comment #16
wim leersI failed to update the exception messages everywhere to have trailing periods. Clearly, the test coverage works :)
Comment #17
catchOnly one actual change to make that I can do on commit, but just things that came up reading through:
three types.
Rest of the docs look good and clearly delineate what to use when.
Long time no see, hook_footer() ;)
Could use a follow-up to put this... somewhere else. Not sure where though. I'd almost leave it using the bc layer.
Not introduced here but should use __DIR__.
The CSS here is only for the permissions and password element - we should probably add it conditionally in the permissions form and as #attached for that element. Again not here though.
Comment #18
catchComment #19
catchFixed #1 on commit.
Committed/pushed to 8.0.x, thanks!
Comment #21
hass commentedHow late is the attachment hook executed? It need to be the very very last...
Comment #22
berdir@hass: No difference to before I think. Use hook_attachments_alter() if you want to be after most other attachment hook implementations. But at least devel also wants to be last, and it just dumps the page content, so you probably want it to win.
Comment #23
hass commentedIt looks like hook_page_top and hook_page_bottom runs after hook_attachments_alter(). And blocks runs after hook_page_bottom(), too. That looks like the wrong order to me as I have no access to the final $page in hook_page_attachments_alter(). Just code wise...
And
$page['#attached']['library'][] = 'google_analytics/google_analytics';is also broken in hook_page_attachments() as it does not add the library to the page.Comment #24
hass commentedComment #25
jhodgdonAs a note, if the docs need adjusting, all of these hooks have now been relocated to core/modules/system/theme.api.php instead of system.api.php where they were. See #2307859: Move theme/render hooks from system.api.php to theme.api.php
Comment #26
catchThat's by design and the entire point of adding this issue.
If there is a specific thing you're tryign to do, and you were previously unable to do it but now cannot, please open a new issue with clear steps to reproduce.
Comment #27
hass commented$page['#attached']['library'][] = 'google_analytics/google_analytics'; is broken in hook_page_attachments() as it does not add the library to the page. This is a bug introduced by the patch here.
Please rollback the patch.
Comment #28
hass commented#2365985: #attached library is broken in hook_page_attachments()/alter()
Please also explain me the design you are refering, too. The case summary does not explain anything and I have no idea why I cannot alter everything.