You are here

public function TokenArgument::processToken in Views Token Argument 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/views/argument_default/TokenArgument.php \Drupal\views_argument_token\Plugin\views\argument_default\TokenArgument::processToken()

Process tokens as raw values.

Parameters

\Drupal\Core\Entity\FieldableEntityInterface $entity: Entity to process.

string $entity_type: Entity type.

string $argument: Argument to process.

Return value

string Processed token.

1 call to TokenArgument::processToken()
TokenArgument::getArgument in src/Plugin/views/argument_default/TokenArgument.php
Return the default argument.

File

src/Plugin/views/argument_default/TokenArgument.php, line 184

Class

TokenArgument
The Token argument default handler.

Namespace

Drupal\views_argument_token\Plugin\views\argument_default

Code

public function processToken(FieldableEntityInterface $entity, $entity_type, $argument) {

  // @todo: $entity_type could potentially be retrieved by checking on $entity.
  $and_or = $this->options['and_or'];
  $field_names = $this
    ->tokenScan($argument);
  foreach ($field_names[$entity_type] as $field_name => $token) {
    $replace_values = [];
    if ($entity
      ->hasField($field_name)) {
      $field_values = $entity
        ->get($field_name)
        ->getValue();
      foreach ($field_values as $field_value) {
        $replace_values[] = array_values($field_value)[0];
      }

      // Replace and implode with , or + for multiple value management.
      $replace = implode($and_or, $replace_values);
      $argument = str_replace($token, $replace, $argument);
    }
  }
  return $argument;
}