You are here

function pathauto_tokens in Pathauto 8

Same name and namespace in other branches
  1. 7 pathauto.tokens.inc \pathauto_tokens()

Implements hook_tokens().

File

./pathauto.tokens.inc, line 27
Token integration for the Pathauto module.

Code

function pathauto_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
  $replacements = [];
  if ($type == 'array' && !empty($data['array'])) {
    $array = $data['array'];
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'join-path':
          $values = [];
          foreach (token_element_children($array) as $key) {
            $value = is_array($array[$key]) ? render($array[$key]) : (string) $array[$key];
            $value = \Drupal::service('pathauto.alias_cleaner')
              ->cleanString($value, $options);
            $values[] = $value;
          }
          $replacements[$original] = implode('/', $values);
          break;
      }
    }
  }
  return $replacements;
}