public function CommentSelection::getReferenceableEntities in Drupal 10
File
- core/
modules/ comment/ src/ Plugin/ EntityReferenceSelection/ CommentSelection.php, line 115
Class
- CommentSelection
- Provides specific access control for the comment entity type.
Namespace
Drupal\comment\Plugin\EntityReferenceSelectionCode
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;
}