diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php index 2531f6a..41fef97 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php @@ -333,12 +333,12 @@ public function generateOutputKey() { */ protected function getCacheTags() { $tags = array(); - $entity_types = $this->view->getEntityTypes(); + $entity_information = $this->view->query->getEntityInformation(); - if (!empty($entity_types)) { + if (!empty($entity_information)) { $tags[$this->view->storage->id()] = TRUE; // Add an ENTIY_TYPE_view tag for each entity type used by this view. - foreach ($entity_types as $type) { + foreach (array_keys($entity_information) as $type) { $tags[$type . '_view'] = TRUE; } 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 7522c3f..71e4c92 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 @@ -1247,8 +1247,8 @@ public function query($get_count = FALSE) { // Make sure each entity table has the base field added so that the // entities can be loaded. - $entity_tables = $this->getEntityTables(); - if ($entity_tables) { + $entity_information = $this->getEntityInformation(); + if ($entity_information) { $params = array(); if ($groupby) { // Handle grouping, by retrieving the minimum entity_id. @@ -1257,10 +1257,10 @@ public function query($get_count = FALSE) { ); } - foreach ($entity_tables as $table_alias => $table) { - $info = entity_get_info($table['entity_type']); - $base_field = empty($table['revision']) ? $info['entity_keys']['id'] : $info['entity_keys']['revision']; - $this->addField($table_alias, $base_field, '', $params); + foreach ($entity_information as $entity_type => $info) { + $entity_info = \Drupal::entityManager()->getDefinition($entity_type); + $base_field = empty($table['revision']) ? $entity_info['entity_keys']['id'] : $entity_info['entity_keys']['revision']; + $this->addField($info['alias'], $base_field, '', $params); } } @@ -1451,9 +1451,11 @@ function execute(ViewExecutable $view) { * Returns an array of all tables from the query that map to an entity type. * * Includes the base table and all relationships, if eligible. + * * Available keys for each table: * - base: The actual base table (i.e. "user" for an author relationship). * - relationship_id: The id of the relationship, or "none". + * - alias: The alias used for the relationship. * - entity_type: The entity type matching the base table. * - revision: A boolean that specifies whether the table is a base table or * a revision table of the entity type. @@ -1461,14 +1463,17 @@ function execute(ViewExecutable $view) { * @return array * An array of table information, keyed by table alias. */ - public function getEntityTables() { + public function getEntityInformation() { // Start with the base table. $entity_tables = array(); $views_data = Views::viewsData(); - $base_table_data = $views_data->get($this->view->storage->get('base_table')); + $base_table = $this->view->storage->get('base_table'); + $base_table_data = $views_data->get($base_table); + if (isset($base_table_data['table']['entity type'])) { - $entity_tables[$this->view->storage->get('base_table')] = array( - 'base' => $this->view->storage->get('base_table'), + $entity_tables[$base_table_data['table']['entity type']] = array( + 'base' => $base_table, + 'alias' => $base_table, 'relationship_id' => 'none', 'entity_type' => $base_table_data['table']['entity type'], 'revision' => FALSE, @@ -1478,9 +1483,10 @@ public function getEntityTables() { foreach ($this->view->relationship as $relationship_id => $relationship) { $table_data = $views_data->get($relationship->definition['base']); if (isset($table_data['table']['entity type'])) { - $entity_tables[$relationship->alias] = array( + $entity_tables[$table_data['table']['entity type']] = array( 'base' => $relationship->definition['base'], 'relationship_id' => $relationship_id, + 'alias' => $relationship->alias, 'entity_type' => $table_data['table']['entity type'], 'revision' => FALSE, ); @@ -1489,7 +1495,7 @@ public function getEntityTables() { // Determine which of the tables are revision tables. foreach ($entity_tables as $table_alias => $table) { - $info = entity_get_info($table['entity_type']); + $info = \Drupal::entityManager()->getDefinition($table['entity_type']); if (isset($info['revision table']) && $info['revision table'] == $table['base']) { $entity_tables[$table_alias]['revision'] = TRUE; } @@ -1506,7 +1512,7 @@ public function getEntityTables() { * $result->_relationship_entities[$relationship_id]; */ function loadEntities(&$results) { - $entity_tables = $this->getEntityTables(); + $entity_tables = $this->getEntityInformation(); // No entity tables found, nothing else to do here. if (empty($entity_tables)) { return; diff --git a/core/modules/views/lib/Drupal/views/ViewExecutable.php b/core/modules/views/lib/Drupal/views/ViewExecutable.php index 45cffaf..d8236cf 100644 --- a/core/modules/views/lib/Drupal/views/ViewExecutable.php +++ b/core/modules/views/lib/Drupal/views/ViewExecutable.php @@ -2225,34 +2225,4 @@ public function buildThemeFunctions($hook) { return $themes; } - /** - * Returns an array of all entity types used by this view. - * - * @return array - * An array of entity types. - */ - public function getEntityTypes() { - // Initialize handlers so we will have any relationships - $this->initHandlers(); - // Start with the base table. - $entity_types = array(); - $views_data = Views::viewsData(); - - // Add the base table. - $base_table_data = $views_data->get($this->storage->get('base_table')); - if (isset($base_table_data['table']['entity type'])) { - $entity_types[] = $base_table_data['table']['entity type']; - } - - // Include all relationships. - foreach ($this->relationship as $relationship) { - $table_data = $views_data->get($relationship->definition['base']); - if (isset($table_data['table']['entity type'])) { - $entity_types[] = $table_data['table']['entity type']; - } - } - - return array_values(array_unique($entity_types)); - } - }