function NodeSelection::createNewEntity

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

Overrides DefaultSelection::createNewEntity

File

core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php, line 41

Class

NodeSelection
Provides specific access control for the node entity type.

Namespace

Drupal\node\Plugin\EntityReferenceSelection

Code

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

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