You are here

function _patterns_replace_tokens in Patterns 6

Same name and namespace in other branches
  1. 5 patterns.module \_patterns_replace_tokens()
  2. 6.2 patterns.module \_patterns_replace_tokens()
  3. 7.2 includes/core/token.inc \_patterns_replace_tokens()
  4. 7 includes/core/token.inc \_patterns_replace_tokens()

Array walk callback to replace tokens inside form values

1 call to _patterns_replace_tokens()
_patterns_recurse_tokens in ./patterns.module
Recurse an array and replace with tokens @ This is used instead of array_walk_recursive because of some strange issues with token_get_values failing.

File

./patterns.module, line 2174
Enables extremely simple adding/removing features to your site with minimal to no configuration

Code

function _patterns_replace_tokens(&$a, &$b, $identifiers = array()) {
  static $count = 0;

  // Replace IDs with identifiers from the current executing pattern
  if (preg_match('/@([a-zA-Z0-9_]+)@/', $a, $match)) {
    $a = str_replace($match[0], $identifiers[$match[1]], $a);
  }
  if (preg_match('/__([a-zA-Z0-9_]+)__/', $b, $match)) {
    $b = str_replace($match[0], $identifiers[$match[1]], $a);
  }

  // Replace tokens
  $a = token_replace($a, 'global', NULL, '@', '@');
  $b = token_replace($b, 'global', NULL, '__', '__');
}