You are here

function user_external_invite_tokens in User External Invite 8

Same name and namespace in other branches
  1. 7.2 user_external_invite.module \user_external_invite_tokens()
  2. 7 user_external_invite.module \user_external_invite_tokens()
  3. 2.0.x user_external_invite.tokens.inc \user_external_invite_tokens()
  4. 1.0.x user_external_invite.module \user_external_invite_tokens()

Implements hook_tokens().

File

./user_external_invite.tokens.inc, line 26
Token integration for the User External Invite module.

Code

function user_external_invite_tokens($type, $tokens, array $data, array $options) {
  $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;
}