function CommentSelection::validateReferenceableEntities

Same name in other branches
  1. 10 core/modules/comment/src/Plugin/EntityReferenceSelection/CommentSelection.php \Drupal\comment\Plugin\EntityReferenceSelection\CommentSelection::validateReferenceableEntities()

Overrides DefaultSelection::validateReferenceableEntities

File

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

Class

CommentSelection
Provides specific access control for the comment entity type.

Namespace

Drupal\comment\Plugin\EntityReferenceSelection

Code

public function validateReferenceableEntities(array $ids) {
    $result = [];
    if ($ids) {
        $target_type = $this->configuration['target_type'];
        $entity_type = $this->entityTypeManager
            ->getDefinition($target_type);
        $query = $this->buildEntityQuery();
        // Mirror the conditions checked in buildEntityQuery().
        if (!$this->currentUser
            ->hasPermission('administer comments')) {
            $query->condition('status', 1);
        }
        $result = $query->condition($entity_type->getKey('id'), $ids, 'IN')
            ->execute();
    }
    return $result;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.