diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 1daa05d..ebfd07f 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1053,32 +1053,23 @@ function node_query_node_access_alter(AlterableInterface $query) { $table_mapping = \Drupal::entityTypeManager()->getStorage('node')->getTableMapping(); $node_base_tables = $table_mapping->getTableNames(); - $potential_base_tables = []; foreach ($tables as $table_info) { if (!($table_info instanceof SelectInterface)) { $table = $table_info['table']; + // Ensure that 'node' and 'node_field_data' are always preferred over + // 'node_revision' and 'node_field_revision'. + if ($table == 'node' || $table == 'node_field_data') { + $base_table = $table; + break; + } // If one of the node base tables are in the query, add it to the list // of possible base tables to join against. if (in_array($table, $node_base_tables)) { - $potential_base_tables[] = $table; + $base_table = $table; } } } - // Ensure that 'node' and 'node_field_data' are always preferred over - // 'node_revision' and 'node_field_revision'. - if (!empty($potential_base_tables)) { - if (in_array('node', $potential_base_tables)) { - $base_table = 'node'; - } - elseif (in_array('node_field_data', $potential_base_tables)) { - $base_table = 'node_field_data'; - } - else { - $base_table = reset($potential_base_tables); - } - } - // Bail out if the base table is missing. if (!$base_table) { throw new Exception(t('Query tagged for node access but there is no node table, specify the base_table using meta data.'));