function FieldPluginBase::getRenderTokens

Same name and namespace in other branches
  1. 11.x core/modules/views/src/Plugin/views/field/FieldPluginBase.php \Drupal\views\Plugin\views\field\FieldPluginBase::getRenderTokens()

File

core/modules/views/src/Plugin/views/field/FieldPluginBase.php, line 1595

Class

FieldPluginBase
Base class for views fields.

Namespace

Drupal\views\Plugin\views\field

Code

public function getRenderTokens($item) {
  $tokens = [];
  if (!empty($this->view->build_info['substitutions'])) {
    $tokens = $this->view->build_info['substitutions'];
  }
  $count = 0;
  foreach ($this->displayHandler
    ->getHandlers('argument') as $arg => $handler) {
    $token = "{{ arguments.{$arg} }}";
    if (!isset($tokens[$token])) {
      $tokens[$token] = '';
    }
    // Use strip tags as there should never be HTML in the path.
    // However, we need to preserve special characters like " that
    // were removed by Html::escape().
    $tokens["{{ raw_arguments.{$arg} }}"] = isset($this->view->args[$count]) ? strip_tags(Html::decodeEntities($this->view->args[$count])) : '';
    $count++;
  }
  // Get flattened set of tokens for any array depth in query parameters.
  if ($request = $this->view
    ->getRequest()) {
    $tokens += $this->getTokenValuesRecursive($request->query
      ->all());
  }
  // Now add replacements for our fields.
  foreach ($this->displayHandler
    ->getHandlers('field') as $field => $handler) {
    /** @var static $handler */
    $placeholder = $handler->getFieldTokenPlaceholder();
    if (isset($handler->last_render)) {
      $tokens[$placeholder] = $handler->last_render;
    }
    else {
      $tokens[$placeholder] = '';
    }
    // We only use fields up to (and including) this one.
    if ($field == $this->options['id']) {
      break;

    }
  }
  // Store the tokens for the row so we can reference them later if necessary.
  $this->view->style_plugin->render_tokens[$this->view->row_index] = $tokens;
  $this->last_tokens = $tokens;
  if (!empty($item)) {
    $this->addSelfTokens($tokens, $item);
  }
  return $tokens;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.