function FieldPluginBase::tokenizeValue

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

Overrides FieldHandlerInterface::tokenizeValue

3 calls to FieldPluginBase::tokenizeValue()
FieldPluginBase::elementClasses in core/modules/views/src/Plugin/views/field/FieldPluginBase.php
Returns the class of the field.
FieldPluginBase::elementLabelClasses in core/modules/views/src/Plugin/views/field/FieldPluginBase.php
Returns the class of the field's label.
FieldPluginBase::elementWrapperClasses in core/modules/views/src/Plugin/views/field/FieldPluginBase.php
Returns the class of the field's wrapper.

File

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

Class

FieldPluginBase
Base class for views fields.

Namespace

Drupal\views\Plugin\views\field

Code

public function tokenizeValue($value, $row_index = NULL) {
    if (strpos($value, '{{') !== FALSE) {
        $fake_item = [
            'alter_text' => TRUE,
            'text' => $value,
        ];
        // Use isset() because empty() will trigger on 0 and 0 is
        // the first row.
        if (isset($row_index) && isset($this->view->style_plugin->render_tokens[$row_index])) {
            $tokens = $this->view->style_plugin->render_tokens[$row_index];
        }
        else {
            // Get tokens from the last field.
            $last_field = end($this->view->field);
            if (isset($last_field->last_tokens)) {
                $tokens = $last_field->last_tokens;
            }
            else {
                $tokens = $last_field->getRenderTokens($fake_item);
            }
        }
        $value = strip_tags($this->renderAltered($fake_item, $tokens));
        if (!empty($this->options['alter']['trim_whitespace'])) {
            $value = trim($value);
        }
    }
    return $value;
}

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