You are here

function pathauto_get_placeholders in Pathauto 6.2

Same name and namespace in other branches
  1. 5.2 pathauto.inc \pathauto_get_placeholders()
  2. 6 pathauto.inc \pathauto_get_placeholders()

Generalized function to get tokens across all Pathauto types.

Parameters

$type: The token type to pass to token_get_values().

$object: The object to pass to token_get_values().

$text: (optional) The string that will be replaced with tokens. If provided and the token_scan() function is available it will be used to trim down the number of tokens that need to be passed to pathauto_clean_token_values().

Return value

Tokens for that object formatted in the way that Pathauto expects to see them.

2 calls to pathauto_get_placeholders()
PathautoTestHelper::assertTokens in ./pathauto.test
pathauto_create_alias in ./pathauto.inc
Apply patterns to create an alias.

File

./pathauto.inc, line 722
Miscellaneous functions for Pathauto.

Code

function pathauto_get_placeholders($type, $object, $text = '', array $options = array()) {
  $options += array(
    'pathauto' => TRUE,
  );
  $full = token_get_values($type, $object, TRUE, $options);

  // Attempt to reduce the tokens to only the ones that will actually be used
  // before passing into pathauto_clean_token_values().
  static $token_scan_exists;
  if (!isset($token_scan_exists)) {
    $token_scan_exists = function_exists('token_scan');
  }
  if ($token_scan_exists && !empty($text)) {
    $used_tokens = token_scan($text);
    foreach ($full->tokens as $index => $token) {
      if (!in_array($token, $used_tokens)) {
        unset($full->tokens[$index]);
        unset($full->values[$index]);
      }
    }
  }
  $tokens = token_prepare_tokens($full->tokens);
  $values = pathauto_clean_token_values($full, $options);
  return array(
    'tokens' => $tokens,
    'values' => $values,
  );
}