Problem/Motivation
View page metatags can be overridden by a view block that is placed on the same page.
Steps to reproduce
Drupal 9.4, Metatags 8.x-1.19
1) Create a view with type page and configure metatags.
2) Create another view with type block, configure metatags and place this block on the view page that you created before.
3) Check your metatags on the page.
Proposed resolution
I figured out that block overrides metatags of view pages. MetatagDisplayExtender::getMetatags() uses self::$firstRowTokens to get metatags for the view.
This variable is defined on metatag_views_views_post_render() hook. And this hook will be run twice (for every view on the page) so the metatags of the page view would be overridden with view block metatags.
Probably there need to rewrite and refactor MetatagDisplayExtender, but for now, I can suggest just a workaround for this problem
Issue fork metatag-3325035
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
panchukThis is just a workaround, if someone has a better solution feel free to suggest it here, thanks. Tested on Drupal 9.4 and Metatag 1.22 and it works well for me.
Comment #4
panchukComment #5
panchukComment #6
damienmckennaThank you for working through this problem!
I don't think the array structure needs to store the ID, because the display is locked to the specific view. As such, it could be shortened to just:
self::$firstRowTokens[$view->current_display] = $first_row_tokens;Secondly, I don't think the view needs to be passed in, it could be taken from the $this object.
Comment #7
panchukAgree with you. So, for now, from my side just hotfix. I will take care of this if no one doesn't until 15 Dec.
Comment #8
panchukI've simplified and cleaned the code. Works well with metatags 1.22.0 and drupal 9.5.2.
@damienmckenna please review it, thanks
Comment #10
damienmckennaCommitted. Thank you.