Hi. I use search_api and facetapi to implement a content search view which is displayed on a panel page. Now I need to have pages with certain active facet items to be set to noindex.

The problem is that I can't alter the meta tags because hook_metatag_metatags_view_alter() has already been called from metatag_panels before the facet items are even processed (or can be altered in hook_facet_items_alter()).

Is there a specific reason why metatag_panels builds the metatags so early in metatag_panels_ctools_render_alter() before any hook_page_build() has run?

metatag itself builds them in metatag_page_build() and metatag_views in metatag_views_page_alter() which is much later than metatag_panels does.

My patch moves most of metatag_panels' meta tag creation code from metatag_panels_ctools_render_alter() to metatag_panels_page_build() which allows altering after most hook_page_build()'s have run. Facet items will be processed at that time and I can alter the tags as required.

Comments

Ronino created an issue. See original summary.

ronino’s picture

Title: Build meta tags for panels much later like metatag and metatag_views do so they can be altered » Build meta tags for panels much later like metatag and metatag_views do so they can be altered after page data has been processed
ronino’s picture

Issue summary: View changes

  • DamienMcKenna committed e0b1e98 on 7.x-1.x authored by Ronino
    Issue #3037874 by Ronino: Build meta tags for Panels much later so they...
damienmckenna’s picture

Version: 7.x-1.25 » 7.x-1.x-dev
Status: Needs review » Fixed
Parent issue: » #2958474: Plan for Metatag 7.x-1.26

Committed. Thanks!

Status: Fixed » Closed (fixed)

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

damienmckenna’s picture

Status: Closed (fixed) » Needs work
Issue tags: +Needs tests

So unfortunately this caused problems and I've had to revert it, see #3104933: Metatag Panels generates invalid argument/illegal string offset errors for details.

It needs extra test coverage to make sure it works correctly and doesn't cause errors.

ronino’s picture

Status: Needs work » Needs review
StatusFileSize
new534 bytes
new2.6 KB

I got three PHP 7.4 notices on pages where metatag_panels_page_build() was called, but metatag_panels_ctools_render_alter() wasn't:
Notice: Trying to access array offset on value of type null in metatag_panels_page_build() (Line 160 of .../metatag/metatag_panels/metatag_panels.module).

This patch fixes this by basically just returning if there are no metatags.

This patch might also fix #3104933: Metatag Panels generates invalid argument/illegal string offset errors which I cannot reproduce. Does anybody know the exact steps to do so?

damienmckenna’s picture

Status: Needs review » Fixed
Issue tags: -Needs tests
Related issues: +#3307363: Plan for Metatag 7.x-1.31

Committed. Thank you.

  • DamienMcKenna committed 37a2bb4 on 7.x-1.x
    Issue #3037874 by Ronino, DamienMcKenna: Build meta tags for panels much...

Status: Fixed » Closed (fixed)

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