diff --git a/core/modules/search/lib/Drupal/search/Plugin/views/argument/Search.php b/core/modules/search/lib/Drupal/search/Plugin/views/argument/Search.php index 8409349..756b8de 100644 --- a/core/modules/search/lib/Drupal/search/Plugin/views/argument/Search.php +++ b/core/modules/search/lib/Drupal/search/Plugin/views/argument/Search.php @@ -74,7 +74,7 @@ public function query($group_by = FALSE) { $this->search_score = $this->query->add_field('', "SUM($search_index.score * $search_total.count)", 'score', array('aggregate' => TRUE)); if (empty($this->query->relationships[$this->relationship])) { - $base_table = $this->query->base_table; + $base_table = $this->view->storage->get('base_table'); } else { $base_table = $this->query->relationships[$this->relationship]['base']; diff --git a/core/modules/search/lib/Drupal/search/Plugin/views/filter/Search.php b/core/modules/search/lib/Drupal/search/Plugin/views/filter/Search.php index 6fc2f8c..8953c91 100644 --- a/core/modules/search/lib/Drupal/search/Plugin/views/filter/Search.php +++ b/core/modules/search/lib/Drupal/search/Plugin/views/filter/Search.php @@ -155,7 +155,7 @@ public function query() { $this->search_score = $this->query->add_field('', "SUM($search_index.score * $search_total.count)", 'score', array('aggregate' => TRUE)); if (empty($this->query->relationships[$this->relationship])) { - $base_table = $this->query->base_table; + $base_table = $this->view->storage->get('base_table'); } else { $base_table = $this->query->relationships[$this->relationship]['base']; diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTidDepth.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTidDepth.php index ba96a52..e8cee6a 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTidDepth.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/views/filter/TaxonomyIndexTidDepth.php @@ -73,8 +73,8 @@ public function query() { $this->tableAlias = $this->relationship; } // If no relationship, then use the alias of the base table. - elseif (isset($this->query->table_queue[$this->query->base_table]['alias'])) { - $this->tableAlias = $this->query->table_queue[$this->query->base_table]['alias']; + elseif (isset($this->query->table_queue[$this->view->storage->get('base_table')]['alias'])) { + $this->tableAlias = $this->query->table_queue[$this->view->storage->get('base_table')]['alias']; } // This should never happen, but if it does, we fail quietly. else { diff --git a/core/modules/views/lib/Drupal/views/ManyToOneHelper.php b/core/modules/views/lib/Drupal/views/ManyToOneHelper.php index 18320eb..1209901 100644 --- a/core/modules/views/lib/Drupal/views/ManyToOneHelper.php +++ b/core/modules/views/lib/Drupal/views/ManyToOneHelper.php @@ -79,7 +79,7 @@ function add_table($join = NULL, $alias = NULL) { // Determine the primary table to seek if (empty($this->handler->query->relationships[$relationship])) { - $base_table = $this->handler->query->base_table; + $base_table = $this->handler->view->storage->get('base_table'); } else { $base_table = $this->handler->query->relationships[$relationship]['base']; diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php index e67614e..0b897ea 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/HandlerBase.php @@ -591,7 +591,7 @@ public function getJoin() { // get the join from this table that links back to the base table. // Determine the primary table to seek if (empty($this->query->relationships[$this->relationship])) { - $base_table = $this->query->base_table; + $base_table = $this->view->storage->get('base_table'); } else { $base_table = $this->query->relationships[$this->relationship]['base']; diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/argument/ArgumentPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/argument/ArgumentPluginBase.php index ef30140..5ec22ea 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/argument/ArgumentPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/argument/ArgumentPluginBase.php @@ -851,7 +851,7 @@ function summary_basics($count_field = TRUE) { // Add the number of nodes counter $distinct = ($this->view->display_handler->getOption('distinct') && empty($this->query->no_distinct)); - $count_alias = $this->query->add_field($this->query->base_table, $this->query->base_field, 'num_records', array('count' => TRUE, 'distinct' => $distinct)); + $count_alias = $this->query->add_field($this->view->storage->get('base_table'), $this->view->storage->get('base_field'), 'num_records', array('count' => TRUE, 'distinct' => $distinct)); $this->query->add_groupby($this->name_alias); if ($count_field) { diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php index 8cda2a9..0f254f8 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php @@ -755,20 +755,15 @@ public function getPlugin($type) { // Query plugins allow specifying a specific query class per base table. if ($type == 'query') { $views_data = views_fetch_data($this->view->storage->get('base_table')); - $name = !empty($views_data['table']['base']['query class']) ? $views_data['table']['base']['query class'] : 'views_query'; + $name = isset($views_data['table']['base']['query_id']) ? $views_data['table']['base']['query_id'] : 'views_query'; } // Plugin instances are stored on the display for re-use. if (!isset($this->plugins[$type][$name])) { $plugin = drupal_container()->get("plugin.manager.views.$type")->createInstance($name); - // Initialize the plugin. Query has a unique method signature. - if ($type == 'query') { - $plugin->init($this->view->storage->get('base_table'), $this->view->storage->get('base_field'), $options['options']); - } - else { - $plugin->init($this->view, $this, $options['options']); - } + // Initialize the plugin. + $plugin->init($this->view, $this, $options['options']); $this->plugins[$type][$name] = $plugin; } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/query/QueryPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/query/QueryPluginBase.php index 0cc44c3..10731b7 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/query/QueryPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/query/QueryPluginBase.php @@ -8,6 +8,7 @@ namespace Drupal\views\Plugin\views\query; use Drupal\views\Plugin\views\PluginBase; +use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\views\ViewExecutable; /** @@ -23,12 +24,13 @@ var $pager = NULL; /** - * Constructor; Create the basic query object and fill with default values. + * Overrides Drupal\views\Plugin\views\PluginBase::init(). */ - public function init($base_table, $base_field, $options) { + public function init(ViewExecutable $view, DisplayPluginBase $display, array $options = array()) { + $this->view = $view; + $this->displayHandler = $display; + $this->setOptionDefaults($this->options, $this->defineOptions()); - $this->base_table = $base_table; - $this->base_field = $base_field; $this->unpackOptions($this->options, $options); } diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php b/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php index ab74e1e..027a7fb 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/query/Sql.php @@ -8,6 +8,7 @@ namespace Drupal\views\Plugin\views\query; use Drupal\Core\Database\Database; +use Drupal\views\Plugin\views\display\DisplayPluginBase; use Drupal\Core\Database\DatabaseExceptionWrapper; use Drupal\views\Plugin\views\join\JoinPluginBase; use Drupal\views\Plugin\views\HandlerBase; @@ -113,12 +114,12 @@ class Sql extends QueryPluginBase { var $no_distinct; /** - * Constructor; Create the basic query object and fill with default values. + * Overrides Drupal\views\Plugin\views\query\QueryPluginBase::init(). */ - public function init($base_table = 'node', $base_field = 'nid', $options) { - parent::init($base_table, $base_field, $options); - $this->base_table = $base_table; // Predefine these above, for clarity. - $this->base_field = $base_field; + public function init(ViewExecutable $view, DisplayPluginBase $display, array $options = array()) { + parent::init($view, $display, $options); + $base_table = $this->view->storage->get('base_table'); + $base_field = $this->view->storage->get('base_field'); $this->relationships[$base_table] = array( 'link' => NULL, 'table' => $base_table, @@ -289,7 +290,7 @@ public function submitOptionsForm(&$form, &$form_state) { */ function add_relationship($alias, JoinPluginBase $join, $base, $link_point = NULL) { if (empty($link_point)) { - $link_point = $this->base_table; + $link_point = $this->view->storage->get('base_table'); } elseif (!array_key_exists($link_point, $this->relationships)) { return FALSE; @@ -323,7 +324,7 @@ function add_relationship($alias, JoinPluginBase $join, $base, $link_point = NUL 'base' => $base, ); - $this->tables[$this->base_table][$alias] = array( + $this->tables[$this->view->storage->get('base_table')][$alias] = array( 'count' => 1, 'alias' => $alias, ); @@ -407,7 +408,7 @@ function queue_table($table, $relationship = NULL, JoinPluginBase $join = NULL, } if (empty($relationship)) { - $relationship = $this->base_table; + $relationship = $this->view->storage->get('base_table'); } if (!array_key_exists($relationship, $this->relationships)) { @@ -415,7 +416,7 @@ function queue_table($table, $relationship = NULL, JoinPluginBase $join = NULL, } if (!$alias && $join && $relationship && !empty($join->adjusted) && $table != $join->table) { - if ($relationship == $this->base_table) { + if ($relationship == $this->view->storage->get('base_table')) { $alias = $table; } else { @@ -439,7 +440,7 @@ function queue_table($table, $relationship = NULL, JoinPluginBase $join = NULL, // If this is a relationship based table, add a marker with // the relationship as a primary table for the alias. if ($table != $alias) { - $this->mark_table($alias, $this->base_table, $alias); + $this->mark_table($alias, $this->view->storage->get('base_table'), $alias); } // If no join is specified, pull it from the table data. @@ -468,7 +469,7 @@ function mark_table($table, $relationship, $alias) { if (empty($this->tables[$relationship][$table])) { if (!isset($alias)) { $alias = ''; - if ($relationship != $this->base_table) { + if ($relationship != $this->view->storage->get('base_table')) { // double underscore will help prevent accidental name // space collisions. $alias = $relationship . '__'; @@ -508,14 +509,14 @@ function mark_table($table, $relationship, $alias) { function ensure_table($table, $relationship = NULL, JoinPluginBase $join = NULL) { // ensure a relationship if (empty($relationship)) { - $relationship = $this->base_table; + $relationship = $this->view->storage->get('base_table'); } // If the relationship is the primary table, this actually be a relationship // link back from an alias. We store all aliases along with the primary table // to detect this state, because eventually it'll hit a table we already // have and that's when we want to stop. - if ($relationship == $this->base_table && !empty($this->tables[$relationship][$table])) { + if ($relationship == $this->view->storage->get('base_table') && !empty($this->tables[$relationship][$table])) { return $this->tables[$relationship][$table]['alias']; } @@ -586,7 +587,7 @@ function ensure_table($table, $relationship = NULL, JoinPluginBase $join = NULL) */ function ensure_path($table, $relationship = NULL, $join = NULL, $traced = array(), $add = array()) { if (!isset($relationship)) { - $relationship = $this->base_table; + $relationship = $this->view->storage->get('base_table'); } if (!array_key_exists($relationship, $this->relationships)) { @@ -646,7 +647,7 @@ function adjust_join($join, $relationship) { } // Adjusts the left table for our relationship. - if ($relationship != $this->base_table) { + if ($relationship != $this->view->storage->get('base_table')) { // If we're linking to the primary table, the relationship to use will // be the prior relationship. Unless it's a direct link. @@ -710,8 +711,8 @@ function get_table_info($table) { } // In rare cases we might *only* have aliased versions of the table. - if (!empty($this->tables[$this->base_table][$table])) { - $alias = $this->tables[$this->base_table][$table]['alias']; + if (!empty($this->tables[$this->view->storage->get('base_table')][$table])) { + $alias = $this->tables[$this->view->storage->get('base_table')][$table]['alias']; if (!empty($this->table_queue[$alias])) { return $this->table_queue[$alias]; } @@ -742,8 +743,8 @@ function get_table_info($table) { */ function add_field($table, $field, $alias = '', $params = array()) { // We check for this specifically because it gets a special alias. - if ($table == $this->base_table && $field == $this->base_field && empty($alias)) { - $alias = $this->base_field; + if ($table == $this->view->storage->get('base_table') && $field == $this->view->storage->get('base_field') && empty($alias)) { + $alias = $this->view->storage->get('base_field'); } if ($table && empty($this->table_queue[$table])) { @@ -1216,10 +1217,10 @@ function compile_fields($query) { $query->addExpression($string, $fieldname, $placeholders); } elseif ($this->distinct && !in_array($fieldname, $this->groupby)) { - $query->addField(!empty($field['table']) ? $field['table'] : $this->base_table, $field['field'], $fieldname); + $query->addField(!empty($field['table']) ? $field['table'] : $this->view->storage->get('base_table'), $field['field'], $fieldname); } elseif (empty($field['aggregate'])) { - $query->addField(!empty($field['table']) ? $field['table'] : $this->base_table, $field['field'], $fieldname); + $query->addField(!empty($field['table']) ? $field['table'] : $this->view->storage->get('base_table'), $field['field'], $fieldname); } if ($this->get_count_optimized) { @@ -1239,7 +1240,7 @@ function compile_fields($query) { public function query($get_count = FALSE) { // Check query distinct value. if (empty($this->no_distinct) && $this->distinct && !empty($this->fields)) { - $base_field_alias = $this->add_field($this->base_table, $this->base_field); + $base_field_alias = $this->add_field($this->view->storage->get('base_table'), $this->view->storage->get('base_field')); $this->add_groupby($base_field_alias); $distinct = TRUE; } @@ -1279,7 +1280,7 @@ public function query($get_count = FALSE) { // Go ahead and build the query. // db_select doesn't support to specify the key, so use getConnection directly. $query = Database::getConnection($target, $key) - ->select($this->base_table, $this->base_table, $options) + ->select($this->view->storage->get('base_table'), $this->view->storage->get('base_table'), $options) ->addTag('views') ->addTag('views_' . $this->view->storage->get('name')); @@ -1442,7 +1443,7 @@ function execute(ViewExecutable $view) { $count_query->addMetaData('view', $view); if (empty($this->options['disable_sql_rewrite'])) { - $base_table_data = views_fetch_data($this->base_table); + $base_table_data = views_fetch_data($this->view->storage->get('base_table')); if (isset($base_table_data['table']['base']['access query tag'])) { $access_tag = $base_table_data['table']['base']['access query tag']; $query->addTag($access_tag); @@ -1540,10 +1541,10 @@ function execute(ViewExecutable $view) { function get_entity_tables() { // Start with the base table. $entity_tables = array(); - $base_table_data = views_fetch_data($this->base_table); + $base_table_data = views_fetch_data($this->view->storage->get('base_table')); if (isset($base_table_data['table']['entity type'])) { - $entity_tables[$this->base_table] = array( - 'base' => $this->base_table, + $entity_tables[$this->view->storage->get('base_table')] = array( + 'base' => $this->view->storage->get('base_table'), 'relationship_id' => 'none', 'entity_type' => $base_table_data['table']['entity type'], 'revision' => FALSE, diff --git a/core/modules/views/lib/Drupal/views/ViewExecutable.php b/core/modules/views/lib/Drupal/views/ViewExecutable.php index b295b9e..5fe8881 100644 --- a/core/modules/views/lib/Drupal/views/ViewExecutable.php +++ b/core/modules/views/lib/Drupal/views/ViewExecutable.php @@ -944,18 +944,7 @@ public function initQuery() { $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->get('base_table'), $this->storage->get('base_field'), $query_options['options']); + $this->query = $this->display_handler->getPlugin('query'); return TRUE; }