Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Updated: Comment 0
Problem/Motivation
For all kind of elements in the HTML header we want to have a clean API to add them. Some examples are feed links and arbitrary meta tags.
Currently there are APIs like drupal_add_feed and drupal_add_html_head
Proposed resolution
Add new value objects like FeedLinkElement, of MetaElement, which can be added to the introduced page object. This will make it really easy for modules like
metatag to deal with the new page flow in Drupal 8
Remaining tasks
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#61 | interdiff.txt | 3.41 KB | dawehner |
#61 | metatag-2218117-61.patch | 37.82 KB | dawehner |
#56 | metaelement-2218117-56.patch | 37.44 KB | dawehner |
#53 | interdiff.txt | 12.89 KB | dawehner |
#53 | metaelement-2218117-53.patch | 37.44 KB | dawehner |
Comments
Comment #1
dawehnerThis is just the first step.
Comment #3
dawehnerMaybe now.
Comment #5
dawehnerOkay agreed, let's also render it.
Comment #7
dawehnerWe need support to be able to alter metatags properly.
Comment #8
Crell CreditAttribution: Crell commentedDisplay the who's what? html.html.twig? What's that?
Otherwise this looks almost exactly like what we pulled out of the HtmlPage issue, so I'm obviously +1 on bringing it back. :-)
Comment #9
Wim LeersComment #10
dawehnerThere is a template html since Drupal 7 which basically prints out the html of the page without the main body area.Note: This is also just moving the comment from within the preprocess function.
Comment #11
Crell CreditAttribution: Crell commentedAhhh... Without context it looked like a service name. :-)
Comment #12
dawehnerHAHA you are so far away from theming :)
Comment #13
sun'name' => 'charset',
'charset' => 'utf-8',
The 'name' is not supposed to be output. Did you test this?
I can't seem to find where the negative weight / high priority is applied? The charset meta tag still needs to come first for security reasons, AFAIK.
Typo in "eturn"
What does this @return?
An array of raw attributes or an array of objects of a certain type?
$this
Can we rename these to have a 'get' method prefix like the other methods?
Bogus phpDoc indentation.
Why is 'rel' optional?
According to http://www.w3.org/TR/html5/document-metadata.html#the-link-element both 'href' and 'rel' are required...?
Shouldn't $rel come first in the signature?
Why is this class named "MetaTag", while the other class is named "Link" (as opposed to "LinkTag") ?
This signature and processing looks a bit weird to me.
Why are we enforcing a 'content' attribute onto each meta tag, if we mix it into attributes anyway?
These two do not necessarily exist.
Shouldn't the MetaTag class much rather have generic set($name, $value) and get($name) methods for arbitrary meta element attributes?
This looks very fragile... what if there are 50 modules that need to add, change, or remove meta tags and links?
Comment #14
Crell CreditAttribution: Crell commentedRe point 1, I don't think meta tags support fully arbitrary attributes. Dave Reid already reviewed the current class in the previous issue and had no further issues beyond what we already took care of. We're aiming for the common case, which is name and content and "sometimes other stuff".
Re point 11, then there's 50 modules that would need to register listeners. Which is no different than today; 50 modules would need to call drupal_add_html_head() from within hook_page_alter() or somewhere. It's no less fragile. And I've never in my life seen a site with 50 modules messing with header tags at once. I don't even think I've seen as many as a half-dozen.
Comment #15
dawehnerWell, note: we always have the full double range available, if really needed.
Comment #16
Crell CreditAttribution: Crell commentedDaniel, are you going to have time to respond to sun's other comments in #13?
Comment #17
dawehnerThank you for your review!
There is no explicit weight in here, but the code flow basically ensures that.
There was indeed no test for that, let's ensure the behavior.
I don't really see why. All the w3 documents talk about HREF first. It as a developer would also expect that tbh.
Great lookup!
I do agree that we should be more consistent. Do you have a preference of MetaTag vs. MetaElement (this is what the standard talks about).
Kind of for DX, as you most of the time want to specify a content.
I wonder whether there are any usecases for meta/link?
Comment #18
Crell CreditAttribution: Crell commentedLooking at the code again... shouldn't the meta and links methods be on HtmlFragment, not HtmlPage? Sam, Mark, and I have been discussing the next step and it involves an HtmlFragmentInterface that has just the getters, including those for sideband data (meta, links, assets, etc.) We may as well move the logic up there now, since it will be there later.
Comment #19
dawehnerI do get the usecase for assets but can you please explain why meta links are useful at all on all fragments and not just html page fragments?
Comment #20
Crell CreditAttribution: Crell commentedThe NodeController::page() controller method specifies link tags for that page specifically. That gets translated to an HtmlFragment before being passed up.
A block that shows a view may also link to an RSS feed, which then gets added as a link, too.
All fragments need to be able to carry out of band data that will then get dissected and reassembled into a single HtmlPage object, with all of that out of band data together.
Comment #21
dawehnerWell, the question I do have though at what point do we stop. I for example have a usecase to pass along the http status code, but is that really something which belongs here?
Comment #22
Crell CreditAttribution: Crell commentedFor now let's just go with the methods where we had them in the original issue before they were removed. When we introduce the interface we can rejigger exactly what goes where. (There will likely be multiple interfaces, but I want to get this moving forward.)
Incremental progress.
Comment #23
dawehnerSo we don't want to add more methods for now? Then let's get the current patch in.
Comment #24
EclipseGc CreditAttribution: EclipseGc commentedrerolled against head.
Eclipse
Comment #25
EclipseGc CreditAttribution: EclipseGc commentedOk, I have moved the methods as Crell asked for in #18. HtmlFragment is a parent class to HtmlPage so the interdiff is ridiculously straight forward.
Eclipse
Comment #28
dawehnerThis could be a random fail, let's reupload the patch.
Let's keep the "random" test failure alive for other people.
Comment #29
Crell CreditAttribution: Crell commentedHuzzah! Thanks, Kris!
Comment #30
EclipseGc CreditAttribution: EclipseGc commentedI see, testbot just hates me...
Eclipse
Comment #31
catchdrupal_pre_render_html() and other uses are not converted. We should at least open a follow-up?
We have feed icon support in the theme layer that consults drupal_get_feeds(). That's ignored here and it's going to result in different behaviour depending which mechanism is used.
Comment #32
alexpottThis issue needs a issue summary and a change record.
Comment #33
catchThis hook is removed but HTML HEAD elements can (and still are in core) added via this mechanism. Those elements won't be alterable either via the event or this hook now.
Comment #34
EclipseGc CreditAttribution: EclipseGc commentedCatch & I discussed this in -wscci and came to the conclusion that #33 is actually already taken care of, so that just leaves 31 & 32.
Eclipse
Comment #35
Crell CreditAttribution: Crell commentedWe discussed this in IRC between catch, dawehner, EclipseGc, and myself. The plan for dealing with feeds is thus:
1) Add a FeedLink extends LinkTag class.
2) Tweak template_preprocess_html to bridge drupal_add_feed the same way we bridge the other head methods.
3) Add an HtmlPage::getFeeds() method (only on that object, not fragment) that returns just those link objects that instanceof FeedLink. This can then be used by the theme layer for generating the RSS icons at the bottom of the page rather than calling drupal_get_feeds().
4) Add the same bridge code to HtmlControllerBase::createHtmlFragment to let feeds get added with the right object.
5) Commit this thing.
6) Factor the render->HtmlFragment code out of HtmlControllerBase to a service in a follow-up (to avoid creep): #2256365: Factor render->fragment code out to a service
7) Factor the read interface of HtmlFragment out to an interface of name TBD, follow-up: #2256373: Factor HtmlFragment out to an interface
Comment #36
dawehnerWe are getting there.
Comment #38
dawehnermeh
Comment #39
tim.plunkettThe substantive changes here are good, just some weird artifacts left over. Note this still needs an issue summary.
Is this a mistake after #2257745: Switch t() to $this->t() in ExceptionController?
...
Do we want to use the 3rd param for explode, like
explode('.', \Drupal::VERSION, 2);
? Also, do we even need that comma in list()?We've been leaving these out now
Comment #41
dawehnerThank you for the review tim!
Comment #43
dawehnerTest html output via a regex, sigh/
Comment #44
dawehnerCurrently working on a change notice.
Comment #45
dawehnerBring it up faster next time, paris!
Comment #46
dawehnerAdded change record.
Comment #47
dawehnerI am so powerful: just created the metaelement.
Comment #48
sunThanks! Would be great to quickly fix the following minor issues prior to commit:
Bogus indentation/formatting of phpDoc comment.
$this
, not self. We can skip the description.Comment #49
alexpottIf we're changing to use MetaElement then what should these functions & parameters be called?
Comment #50
alexpottAnd we still need an issue summary
Comment #51
webchickComment #52
dawehnerComment #53
dawehnerHere is the recent version of the patch.
Comment #54
Crell CreditAttribution: Crell commentedAssuming the bot is OK...
Comment #56
dawehnerSeems like a random fail.
Comment #57
dawehner.
Comment #58
EclipseGc CreditAttribution: EclipseGc commentedComment #59
sun+1 Looks great to me now.
Comment #60
catchMinor, but this could be $page->getFeedLinks() no?
I'm not sure about putting the links/feeds onto the page object in preprocess, seems like it'd be better in a step just before preprocess, but not sure what step that should be... - maybe a followup? I realise this is a bc shim but feels quite far off actually removing that yet.
Comment #61
dawehnerComment #62
Crell CreditAttribution: Crell commented#61 makes sense.
I don't think the BC shim is better/worse in either place, so, meh.
Comment #63
dawehnerBtw. this is not BC at the moment, because for example /node relies on it. Just experienced that during development.
Comment #64
catchYes good point, shouldn't call something backwards compatibility if it's the only thing keeping an entire subsystem working.
I'm OK with this now but we need an explicit follow-up/plan to make it actually possible to remove the old deprecated stuff - that's not linked from the summary/related issues at all.
Comment #65
Crell CreditAttribution: Crell commentedI updated the existing follow-up at #2256365: Factor render->fragment code out to a service to clarify that it should be a complete render->fragment converter, including #attached. That should be sufficient for #64.
Comment #66
webchickThis smells catch-ish.
Comment #68
catchOne more thing, this comment isn't describing the problem, the issue is in drupal_render_collect_attached() and that needing to be connected to HtmlFragment, rather than legacy calls to drupal_add_feed(). Views doesn't call drupal_add_feed() any more, it uses #attached['drupal_add_feed'].
I updated the comment on commit since otherwise this patch could end up breaking the record for most times RTBC without actually being RTBC, if it hasn't already.