diff --git a/core/modules/comment/src/Plugin/entity_reference/selection/CommentSelection.php b/core/modules/comment/src/Plugin/entity_reference/selection/CommentSelection.php index 7a627d1..4b1586e 100644 --- a/core/modules/comment/src/Plugin/entity_reference/selection/CommentSelection.php +++ b/core/modules/comment/src/Plugin/entity_reference/selection/CommentSelection.php @@ -44,31 +44,20 @@ public function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') { */ public function entityQueryAlter(SelectInterface $query) { $tables = $query->getTables(); - $base_table = $tables['base_table']['alias']; + $data_table = 'comment_field_data'; + if (!isset($tables['comment_field_data']['alias'])) { + // When no conditions used the comment data table joined it manually to + // allow node access processing. + $query->innerJoin($data_table, NULL, "base_table.cid = $data_table.cid AND $data_table.default_langcode = 1"); + } // The Comment module doesn't implement any proper comment access, // and as a consequence doesn't make sure that comments cannot be viewed // when the user doesn't have access to the node. - $node_alias = $query->innerJoin('node_field_data', 'n', '%alias.nid = ' . $base_table . '.entity_id AND ' . $base_table . ".entity_type = 'node'"); + $node_alias = $query->innerJoin('node_field_data', 'n', '%alias.nid = ' . $data_table . '.entity_id AND ' . $data_table . ".entity_type = 'node'"); // Pass the query to the node access control. $this->reAlterQuery($query, 'node_access', $node_alias); - // Alas, the comment entity exposes a bundle, but doesn't have a bundle - // column in the database. We have to alter the query ourselves to go fetch - // the bundle. - $conditions = &$query->conditions(); - foreach ($conditions as $key => &$condition) { - if ($key !== '#conjunction' && is_string($condition['field']) && $condition['field'] === 'node_type') { - $condition['field'] = $node_alias . '.type'; - foreach ($condition['value'] as &$value) { - if (substr($value, 0, 13) == 'comment_node_') { - $value = substr($value, 13); - } - } - break; - } - } - // Passing the query to node_query_node_access_alter() is sadly // insufficient for nodes. // @see SelectionEntityTypeNode::entityQueryAlter()