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.
Problem/Motivation
Using metatag 8.x-1.10 we've got some custom code that does some trickery to change the page title. But it appears that #3099168: Remove "title" meta tag, leave the regular title tag broke the assumptions that the custom code was making.
The patch attached is a failing test on 8.x-1.x but will pass on 8.x-1.10.
Proposed resolution
The custom code should either convert the hook_page_attachments_alter() implementation into a hook_metatags_attachments_alter() OR adjust the contents of drupal_static('metatag_attachments')
and not try to change $attachments.
This issue now:
- tidies up the comments added by #3099168: Remove "title" meta tag, leave the regular title tag to be a bit clearer as they seemed (to me) to imply metatag_preprocess_html() comes before metatag_page_attachments() which is not the case
- Improves the logic in metatag_page_attachments() to do less iterating.
- Adds an integration test for modules implementing
hook_metatags_attachments_alter()
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comment | File | Size | Author |
---|---|---|---|
#14 | 3153911-14.patch | 6.06 KB | alexpott |
| |||
#14 | 13-14-interdiff.txt | 1.32 KB | alexpott |
#13 | 10-11-interdiff.txt | 1011 bytes | alexpott |
#13 | 3153911-11.patch | 5.91 KB | alexpott |
#10 | 3153911-10.patch | 5.98 KB | alexpott |
Comments
Comment #2
alexpottHere's a patch which shows the problem.
Comment #3
alexpottI can't run a test with DrupalCI against 8.x-1.10 but here's the output:
Comment #5
alexpottAfter spending sometime in the debugger I can see where the implementation of metatag_test_integration_page_attachments_alter() is incorrect. It's expecting
$attachments['#attached']['html_head']
to still have a title attribute. Since #3099168: Remove "title" meta tag, leave the regular title tag it no longer does. So the code doesn't work as expected. If we change it as per the patch attached here - everything seems to work.Perhaps this is better implemented as hook_metatags_attachments_alter() in the first place.
Comment #7
mrinalini9 CreditAttribution: mrinalini9 at Srijan | A Material+ Company for Drupal India Association commentedFixing test case failure issue in #5, please review.
Comment #8
alexpott@mrinalini9 that fix looks important for the metatag module. This issue was created to explore modules that implement hook_page_attachments_alter() and change metatag related stuff. You could check the metatag issue queue and if there is not an issue already you could file an issue to correct #7.
Comment #9
alexpottThis will fail tests because HEAD metatag is failing tests due to #7. But that should be fixed in another issue.
Comment #10
alexpottReading
metatag_preprocess_html()
again I think we need to be clearer about whose attachments we are reading from. In $variables there's$variables['#attached']
and$variables['html_attributes']
and $attributes looks like the same variable as it is inmetatag_page_attachments()
.I think we should copy the approach from
metatag_page_attachments()
and call them$metatag_attachments
Comment #13
alexpottChanging the hook implementation to the correct
hook_metatags_attachments_alter()
so now the module has test coverage of this hook.Comment #14
alexpottAnd finally lets tidy up the test.
Comment #17
DamienMcKennaThe tests have been fixed in the 8.x-1.x branch, back to fixing this.
Comment #18
alexpottThis should pass now...
Comment #19
DamienMcKennaNice work, thank you! Committed.