You are here

protected function ViewExecutable::_buildArguments in Views (for Drupal 7) 8.3

Build all the arguments.

2 calls to ViewExecutable::_buildArguments()
ViewExecutable::build in lib/Drupal/views/ViewExecutable.php
Build the query for the view.
ViewExecutable::buildTitle in lib/Drupal/views/ViewExecutable.php
Force the view to build a title.

File

lib/Drupal/views/ViewExecutable.php, line 819
Definition of Drupal\views\ViewExecutable.

Class

ViewExecutable
An object to contain all of the data to generate a view, plus the member functions to build the view query, execute the query and render the output.

Namespace

Drupal\views

Code

protected function _buildArguments() {

  // Initially, we want to build sorts and fields. This can change, though,
  // if we get a summary view.
  if (empty($this->argument)) {
    return TRUE;
  }

  // build arguments.
  $position = -1;

  // Create a title for use in the breadcrumb trail.
  $title = $this->display_handler
    ->getOption('title');
  $this->build_info['breadcrumb'] = array();
  $breadcrumb_args = array();
  $substitutions = array();
  $status = TRUE;

  // Iterate through each argument and process.
  foreach ($this->argument as $id => $arg) {
    $position++;
    $argument =& $this->argument[$id];
    if ($argument
      ->broken()) {
      continue;
    }
    $argument
      ->setRelationship();
    $arg = isset($this->args[$position]) ? $this->args[$position] : NULL;
    $argument->position = $position;
    if (isset($arg) || $argument
      ->has_default_argument()) {
      if (!isset($arg)) {
        $arg = $argument
          ->get_default_argument();

        // make sure default args get put back.
        if (isset($arg)) {
          $this->args[$position] = $arg;
        }

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

      // Set the argument, which will also validate that the argument can be set.
      if (!$argument
        ->set_argument($arg)) {
        $status = $argument
          ->validateFail($arg);
        break;
      }
      if ($argument
        ->is_exception()) {
        $arg_title = $argument
          ->exception_title();
      }
      else {
        $arg_title = $argument
          ->get_title();
        $argument
          ->query($this->display_handler
          ->useGroupBy());
      }

      // Add this argument's substitution
      $substitutions['%' . ($position + 1)] = $arg_title;
      $substitutions['!' . ($position + 1)] = strip_tags(decode_entities($arg));

      // Since we're really generating the breadcrumb for the item above us,
      // check the default action of this argument.
      if ($this->display_handler
        ->usesBreadcrumb() && $argument
        ->uses_breadcrumb()) {
        $path = $this
          ->getUrl($breadcrumb_args);
        if (strpos($path, '%') === FALSE) {
          if (!empty($argument->options['breadcrumb_enable']) && !empty($argument->options['breadcrumb'])) {
            $breadcrumb = $argument->options['breadcrumb'];
          }
          else {
            $breadcrumb = $title;
          }
          $this->build_info['breadcrumb'][$path] = str_replace(array_keys($substitutions), $substitutions, $breadcrumb);
        }
      }

      // Allow the argument to muck with this breadcrumb.
      $argument
        ->set_breadcrumb($this->build_info['breadcrumb']);

      // Test to see if we should use this argument's title
      if (!empty($argument->options['title_enable']) && !empty($argument->options['title'])) {
        $title = $argument->options['title'];
      }
      $breadcrumb_args[] = $arg;
    }
    else {

      // determine default condition and handle.
      $status = $argument
        ->default_action();
      break;
    }

    // Be safe with references and loops:
    unset($argument);
  }

  // set the title in the build info.
  if (!empty($title)) {
    $this->build_info['title'] = $title;
  }

  // Store the arguments for later use.
  $this->build_info['substitutions'] = $substitutions;
  return $status;
}