function CommentSelection::createNewEntity

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

Overrides DefaultSelection::createNewEntity

File

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

Class

CommentSelection
Provides specific access control for the comment entity type.

Namespace

Drupal\comment\Plugin\EntityReferenceSelection

Code

public function createNewEntity($entity_type_id, $bundle, $label, $uid) {
    $comment = parent::createNewEntity($entity_type_id, $bundle, $label, $uid);
    // In order to create a referenceable comment, it needs to published.
    
    /** @var \Drupal\comment\CommentInterface $comment */
    $comment->setPublished();
    return $comment;
}

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