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

Command icon 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

Panchuk created an issue. See original summary.

panchuk’s picture

Assigned: panchuk » Unassigned
Status: Active » Needs review

This 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.

panchuk’s picture

Issue summary: View changes
panchuk’s picture

Version: 8.x-1.19 » 8.x-1.x-dev
damienmckenna’s picture

Status: Needs review » Needs work

Thank 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.

panchuk’s picture

Agree with you. So, for now, from my side just hotfix. I will take care of this if no one doesn't until 15 Dec.

panchuk’s picture

Status: Needs work » Needs review

I've simplified and cleaned the code. Works well with metatags 1.22.0 and drupal 9.5.2.

@damienmckenna please review it, thanks

damienmckenna’s picture

Title: View page metatags can be overridden by view block that placed on same page. » View page meta tags can be overridden by view block that placed on same page.
Status: Needs review » Fixed
Parent issue: » #3313052: Plan for Metatag 8.x-1.23

Committed. Thank you.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.