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.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | metatag-build_panel_tags_later-3037874-8.patch | 2.6 KB | ronino |
| #8 | metatag-interdiff-3037874-1-8.txt | 534 bytes | ronino |
Comments
Comment #2
ronino commentedComment #3
ronino commentedComment #5
damienmckennaCommitted. Thanks!
Comment #7
damienmckennaSo 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.
Comment #8
ronino commentedI 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?
Comment #9
damienmckennaCommitted. Thank you.