function CommentSelection::validateReferenceableNewEntities

Same name in other branches
  1. 9 core/modules/comment/src/Plugin/EntityReferenceSelection/CommentSelection.php \Drupal\comment\Plugin\EntityReferenceSelection\CommentSelection::validateReferenceableNewEntities()
  2. 8.9.x core/modules/comment/src/Plugin/EntityReferenceSelection/CommentSelection.php \Drupal\comment\Plugin\EntityReferenceSelection\CommentSelection::validateReferenceableNewEntities()
  3. 10 core/modules/comment/src/Plugin/EntityReferenceSelection/CommentSelection.php \Drupal\comment\Plugin\EntityReferenceSelection\CommentSelection::validateReferenceableNewEntities()

Overrides DefaultSelection::validateReferenceableNewEntities

File

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

Class

CommentSelection
Provides specific access control for the comment entity type.

Namespace

Drupal\comment\Plugin\EntityReferenceSelection

Code

public function validateReferenceableNewEntities(array $entities) {
    $entities = parent::validateReferenceableNewEntities($entities);
    // Mirror the conditions checked in buildEntityQuery().
    if (!$this->currentUser
        ->hasPermission('administer comments')) {
        $entities = array_filter($entities, function ($comment) {
            
            /** @var \Drupal\comment\CommentInterface $comment */
            return $comment->isPublished();
        });
    }
    return $entities;
}

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