1 views.tokens.inc views_tokens($type, $tokens, array $data = array(), array $options = array())

Implements hook_tokens().

File

core/modules/views/views.tokens.inc, line 44
Token integration for the views module.

Code

function views_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $url_options = array('absolute' => TRUE);
  if (isset($options['language'])) {
    $url_options['language'] = $options['language'];
  }
  $sanitize = !empty($options['sanitize']);
  $langcode = isset($options['language']) ? $options['language']->langcode : NULL;

  $replacements = array();

  if ($type == 'view' && !empty($data['view'])) {
    $view = $data['view'];

    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'name':
          $replacements[$original] = $sanitize ? check_plain($view->human_name) : $view->human_name;
          break;

        case 'description':
          $replacements[$original] = $sanitize ? check_plain($view->description) : $view->description;
          break;

        case 'machine-name':
          $replacements[$original] = $view->name;
          break;

        case 'title':
          $title = $view->get_title();
          $replacements[$original] = $sanitize ? check_plain($title) : $title;
          break;

        case 'url':
          if ($path = $view->get_url()) {
            $replacements[$original] = url($path, $url_options);
          }
          break;
      }
    }

    // [view:url:*] nested tokens. This only works if Token module is installed.
    if ($url_tokens = token_find_with_prefix($tokens, 'url')) {
      if ($path = $view->get_url()) {
        $replacements += token_generate('url', $url_tokens, array('path' => $path), $options);
      }
    }
  }

  return $replacements;
}