Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CommentSelection.php

function CommentSelection::getReferenceableEntities

Overrides DefaultSelection::getReferenceableEntities

1 call to CommentSelection::getReferenceableEntities()
CommentSelection::countReferenceableEntities in core/modules/comment/src/Plugin/EntityReferenceSelection/CommentSelection.php
Counts entities that are referenceable.

File

core/modules/comment/src/Plugin/EntityReferenceSelection/CommentSelection.php, line 144

Class

CommentSelection
Provides specific access control for the comment entity type.

Namespace

Drupal\comment\Plugin\EntityReferenceSelection

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal