You are here

protected function FieldPluginBase::getTokenValuesRecursive 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::getTokenValuesRecursive()

Recursive function to add replacements for nested query string parameters.

E.g. if you pass in the following array: array( 'foo' => array( 'a' => 'value', 'b' => 'value', ), 'bar' => array( 'a' => 'value', 'b' => array( 'c' => value, ), ), );

Would yield the following array of tokens: array( '%foo_a' => 'value' '%foo_b' => 'value' '%bar_a' => 'value' '%bar_b_c' => 'value' );

Parameters

$array: An array of values.

$parent_keys: An array of parent keys. This will represent the array depth.

Return value

An array of available tokens, with nested keys representative of the array structure.

1 call to FieldPluginBase::getTokenValuesRecursive()
FieldPluginBase::getRenderTokens in core/modules/views/src/Plugin/views/field/FieldPluginBase.php
Gets the 'render' tokens to use for advanced rendering.

File

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

Class

FieldPluginBase
Base class for views fields.

Namespace

Drupal\views\Plugin\views\field

Code

protected function getTokenValuesRecursive(array $array, array $parent_keys = array()) {
  $tokens = array();
  foreach ($array as $param => $val) {
    if (is_array($val)) {

      // Copy parent_keys array, so we don't affect other elements of this
      // iteration.
      $child_parent_keys = $parent_keys;
      $child_parent_keys[] = $param;

      // Get the child tokens.
      $child_tokens = $this
        ->getTokenValuesRecursive($val, $child_parent_keys);

      // Add them to the current tokens array.
      $tokens += $child_tokens;
    }
    else {

      // Create a token key based on array element structure.
      $token_string = !empty($parent_keys) ? implode('.', $parent_keys) . '.' . $param : $param;
      $tokens['{{ arguments.' . $token_string . ' }}'] = strip_tags(Html::decodeEntities($val));
    }
  }
  return $tokens;
}