Closed (fixed)
Project:
Metatag
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
19 Oct 2012 at 18:36 UTC
Updated:
30 Oct 2012 at 12:02 UTC
Jump to comment: Most recent file
Comments
Comment #1
alexweber commentedAttached is a simple patch which adds a drupal_alter() both when loading the metatag to add to preprocess and also when viewing in the admin overview page.
API docs were also updated to demonstrate.
Comment #2
damienmckennaPlease explain exactly what you're trying to alter as I'm a little confused as to your needs. Thanks.
Comment #3
alexweber commented@DamienMcKenna I'm trying to alter a metatag's value before getting displayed (post-token replacement).
Basically if the pattern is set to: "[current-page:title] | [site:name]", it will resolve to "Page Title | Site Name". I have a specific use-case for a project where they want to be able to dynamically alter the metatag in certain situations. So, for the sake of simplicity, if its node/1 the title will instead be "Foo | Site Name".
Granted this is a very specific use-case, but that doesn't change the fact that, going with the Drupal way of doing things, it would be nice to have an "alter" hook for metatags. The fact that there's actually a "metatag_alter" described in "metatag_hook_info()" seems to corroborate that this was, in fact, planned.
However, despite being mentioned in hook_hook_info(), there is nowhere in the code that allows metatags to be altered (strangely enough except for taxonomy terms where theres a hook_metatag_view_alter() implemented).
Therefore, all I did was add a drupal_alter() in 2 places in the code that allows modules to alter metatags.
Does this make sense?
Comment #4
damienmckennaYou should be using hook_metatag_metatags_view_alter() to modify meta tags, fyi this function is loaded . You can use theme functions (!) if you need to override individual meta tags one at a time.
I've added the missing $instance value to the drupal_alter call (#1818240: Add $instance to drupal_alter(metatag_metatags_view)), so here's some documentation.
Comment #5
damienmckennaI've committed the patch from #4.
Comment #6
alexweber commentedThanks!
Comment #7
damienmckennaAlso: #1818762: Update hook_hook_info()
Comment #8
damienmckennaThis has been released in 1.0-beta2: http://drupal.org/node/1826908