You are here

function hook_metatag_pattern_alter in Metatag 7

Allows modules to alter defined token patterns and values before replacement.

The metatag module defines default token patterns replacements depending on the different configuration instances (contexts, such as global, node, ...). This hook provides an opportunity for other modules to alter the patterns or the values for replacements, before tokens are replaced (token_replace).

See facetapi and facetapi_bonus modules for an example of implementation.

Parameters

string $pattern: A string potentially containing replaceable tokens. The pattern could also be altered by reference, allowing modules to implement further logic, such as tokens lists or masks/filters.

array $types: Corresponds to the 'token data' property of the $options object. (optional) An array of keyed objects. For simple replacement scenarios 'node', 'user', and others are common keys, with an accompanying node or user object being the value. Some token types, like 'site', do not require any explicit information from $data and can be replaced even if it is empty.

string $tag_name: The name of the meta tag being altered.

See also

DrupalTextMetaTag::getValue()

1 invocation of hook_metatag_pattern_alter()
DrupalTextMetaTag::getValue in ./metatag.inc
Get the string value of this meta tag.

File

./metatag.api.php, line 401
API documentation for the Metatag module.

Code

function hook_metatag_pattern_alter(&$pattern, array &$types, $tag_name) {
  if (strpos($pattern, 'token_type1') !== FALSE) {
    $types['token_type1'] = "data to be used in hook_tokens for replacement";
  }
  if (strpos($pattern, 'token_type2') !== FALSE) {

    // Load something or do some operations.
    $types['token_type2'] = array(
      "Then fill in the array with the right data",
    );

    // $pattern could also be altered, for example, strip off [token_type3].
    $pattern = str_replace('[token_type3]', '', $pattern);
  }
}