You are here

public function FieldPluginBase::getRenderTokens in Zircon Profile 8

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

Gets the 'render' tokens to use for advanced rendering.

This runs through all of the fields and arguments that are available and gets their values. This will then be used in one giant str_replace().

Parameters

mixed $item: The item to render.

Return value

array An array of available tokens

Overrides FieldHandlerInterface::getRenderTokens

3 calls to FieldPluginBase::getRenderTokens()
ContextualLinks::render in core/modules/contextual/src/Plugin/views/field/ContextualLinks.php
Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::render().
FieldPluginBase::renderText in core/modules/views/src/Plugin/views/field/FieldPluginBase.php
Performs an advanced text render for the item.
Links::getLinks in core/modules/views/src/Plugin/views/field/Links.php
Gets the list of links used by this field.

File

core/modules/views/src/Plugin/views/field/FieldPluginBase.php, line 1550
Contains \Drupal\views\Plugin\views\field\FieldPluginBase.

Class

FieldPluginBase
Base class for views fields.

Namespace

Drupal\views\Plugin\views\field

Code

public function getRenderTokens($item) {
  $tokens = array();
  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 SafeMarkup::checkPlain().
    $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;
}