Skip to content
Snippets Groups Projects

Issue #3238915: Refactor (if feasible) uses of the jQuery ready function to use VanillaJS

Closed Issue #3238915: Refactor (if feasible) uses of the jQuery ready function to use VanillaJS
Closed Harumi Jang requested to merge issue/drupal-3238915:3238915-refactor-if-feasible into 9.3.x
2 files
+ 82
13
Compare changes
  • Side-by-side
  • Inline
Files
2
  • 3f9d9b44
    Issue #2958241 by fjgarlin, thetwentyseven, Wim Leers, joachim,... · 3f9d9b44
    catch authored
    Issue #2958241 by fjgarlin, thetwentyseven, Wim Leers, joachim, immaculatexavier, fulgent, larowlan, lastlink, andypost, nnevill: Impossible to reply to comments: commented entity considered unreferencable because CommentSelection::entityQueryAlter() joins on {node_field_data} table
@@ -2,6 +2,7 @@
@@ -2,6 +2,7 @@
namespace Drupal\comment\Plugin\EntityReferenceSelection;
namespace Drupal\comment\Plugin\EntityReferenceSelection;
 
use Drupal\Component\Utility\Html;
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\Core\Database\Query\SelectInterface;
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
use Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection;
use Drupal\comment\CommentInterface;
use Drupal\comment\CommentInterface;
@@ -76,19 +77,75 @@ public function entityQueryAlter(SelectInterface $query) {
@@ -76,19 +77,75 @@ public function entityQueryAlter(SelectInterface $query) {
$query->innerJoin($data_table, NULL, "[base_table].[cid] = [$data_table].[cid] AND [$data_table].[default_langcode] = 1");
$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,
// Find the host entity type the comment field is on.
// and as a consequence doesn't make sure that comments cannot be viewed
$comment = $this->getConfiguration()['entity'];
// when the user doesn't have access to the node.
if ($comment) {
$node_alias = $query->innerJoin('node_field_data', 'n', "[%alias].[nid] = [$data_table].[entity_id] AND [$data_table].[entity_type] = 'node'");
$host_entity_type_id = $comment->getCommentedEntityTypeId();
// Pass the query to the node access control.
$this->reAlterQuery($query, 'node_access', $node_alias);
/** @var \Drupal\Core\Entity\EntityTypeInterface $host_entity_type */
$host_entity_type = $this->entityTypeManager->getDefinition($host_entity_type_id);
// Passing the query to node_query_node_access_alter() is sadly
$host_entity_field_data_table = $host_entity_type->getDataTable();
// insufficient for nodes.
// @see \Drupal\node\Plugin\EntityReferenceSelection\NodeSelection::buildEntityQuery()
// Not all entities have a data table, so check first.
if (!$this->currentUser->hasPermission('bypass node access') && !$this->moduleHandler->hasImplementations('node_grants')) {
if ($host_entity_field_data_table) {
$query->condition($node_alias . '.status', 1);
$id_key = $host_entity_type->getKey('id');
 
 
// The Comment module doesn't implement per-comment access, so it
 
// checks instead that the user has access to the host entity.
 
$entity_alias = $query->innerJoin($host_entity_field_data_table, 'n', "[%alias].[$id_key] = [$data_table].[entity_id] AND [$data_table].[entity_type] = '$host_entity_type_id'");
 
// Pass the query to the entity access control.
 
$this->reAlterQuery($query, $host_entity_type_id . '_access', $entity_alias);
 
 
// Additional checks for "node" entities.
 
if ($host_entity_type_id === 'node') {
 
// Passing the query to node_query_node_access_alter() is sadly
 
// insufficient for nodes.
 
// @see \Drupal\node\Plugin\EntityReferenceSelection\NodeSelection::buildEntityQuery()
 
if (!$this->currentUser->hasPermission('bypass node access') && !$this->moduleHandler->hasImplementations('node_grants')) {
 
$query->condition($entity_alias . '.status', 1);
 
}
 
}
 
}
 
}
 
}
 
 
/**
 
* {@inheritdoc}
 
*/
 
public function getReferenceableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) {
 
$target_type = $this->getConfiguration()['target_type'];
 
 
$query = $this->buildEntityQuery($match, $match_operator);
 
if ($limit > 0) {
 
$query->range(0, $limit);
}
}
 
 
$result = $query->execute();
 
 
if (empty($result)) {
 
return [];
 
}
 
 
$options = [];
 
$entities = $this->entityTypeManager->getStorage($target_type)->loadMultiple($result);
 
foreach ($entities as $entity_id => $entity) {
 
// Additional access check as comments might be attached to entities
 
// which the current user does not have access to.
 
if ($entity->access('view', $this->currentUser)) {
 
$bundle = $entity->bundle();
 
$options[$bundle][$entity_id] = Html::escape($this->entityRepository->getTranslationFromContext($entity)->label() ?? '');
 
}
 
}
 
 
return $options;
 
}
 
 
/**
 
* {@inheritdoc}
 
*/
 
public function countReferenceableEntities($match = NULL, $match_operator = 'CONTAINS') {
 
$options = $this->getReferenceableEntities($match, $match_operator);
 
return count($options, COUNT_RECURSIVE) - count($options);
}
}
}
}
Loading