You are here

public function ArgumentPluginBase::getValue in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php \Drupal\views\Plugin\views\argument\ArgumentPluginBase::getValue()

Get the value of this argument.

File

core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php, line 1049

Class

ArgumentPluginBase
Base class for argument (contextual filter) handler plugins.

Namespace

Drupal\views\Plugin\views\argument

Code

public function getValue() {

  // If we already processed this argument, we're done.
  if (isset($this->argument)) {
    return $this->argument;
  }

  // Otherwise, we have to pretend to process ourselves to find the value.
  $value = NULL;

  // Find the position of this argument within the view.
  $position = 0;
  foreach ($this->view->argument as $id => $argument) {
    if ($id == $this->options['id']) {
      break;
    }
    $position++;
  }
  $arg = isset($this->view->args[$position]) ? $this->view->args[$position] : NULL;
  $this->position = $position;

  // Clone ourselves so that we don't break things when we're really
  // processing the arguments.
  $argument = clone $this;
  if (!isset($arg) && $argument
    ->hasDefaultArgument()) {
    $arg = $argument
      ->getDefaultArgument();

    // remember that this argument was computed, not passed on the URL.
    $this->is_default = TRUE;
  }

  // Set the argument, which will also validate that the argument can be set.
  if ($argument
    ->setArgument($arg)) {
    $value = $argument->argument;
  }
  unset($argument);
  return $value;
}