You are here

public function ViewExecutable::initQuery in Views (for Drupal 7) 8.3

Do some common building initialization.

2 calls to ViewExecutable::initQuery()
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 930
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

public function initQuery() {
  if (!empty($this->query)) {
    $class = get_class($this->query);
    if ($class && $class != 'stdClass') {

      // return if query is already initialized.
      return TRUE;
    }
  }

  // Create and initialize the query object.
  $views_data = views_fetch_data($this->storage->base_table);
  $this->storage->base_field = !empty($views_data['table']['base']['field']) ? $views_data['table']['base']['field'] : '';
  if (!empty($views_data['table']['base']['database'])) {
    $this->base_database = $views_data['table']['base']['database'];
  }

  // Load the options.
  $query_options = $this->display_handler
    ->getOption('query');

  // Create and initialize the query object.
  $plugin = !empty($views_data['table']['base']['query_id']) ? $views_data['table']['base']['query_id'] : 'views_query';
  $this->query = views_get_plugin('query', $plugin);
  if (empty($this->query)) {
    return FALSE;
  }
  $this->query
    ->init($this->storage->base_table, $this->storage->base_field, $query_options['options']);
  return TRUE;
}