public function NodeSelection::createNewEntity in Drupal 9
Same name and namespace in other branches
- 8 core/modules/node/src/Plugin/EntityReferenceSelection/NodeSelection.php \Drupal\node\Plugin\EntityReferenceSelection\NodeSelection::createNewEntity()
 
Creates a new entity object that can be used as a valid reference.
Parameters
string $entity_type_id: The entity type ID.
string $bundle: The bundle name.
string $label: The entity label.
int $uid: The entity owner ID, if the entity type supports it.
Return value
\Drupal\Core\Entity\EntityInterface An unsaved entity object.
Overrides DefaultSelection::createNewEntity
File
- core/
modules/ node/ src/ Plugin/ EntityReferenceSelection/ NodeSelection.php, line 40  
Class
- NodeSelection
 - Provides specific access control for the node entity type.
 
Namespace
Drupal\node\Plugin\EntityReferenceSelectionCode
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;
}