function DefaultSelection::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 SelectionWithAutocreateInterface::createNewEntity
6 calls to DefaultSelection::createNewEntity()
- CommentSelection::createNewEntity in core/
modules/ comment/ src/ Plugin/ EntityReferenceSelection/ CommentSelection.php  - Creates a new entity object that can be used as a valid reference.
 - FileSelection::createNewEntity in core/
modules/ file/ src/ Plugin/ EntityReferenceSelection/ FileSelection.php  - Creates a new entity object that can be used as a valid reference.
 - MediaSelection::createNewEntity in core/
modules/ media/ src/ Plugin/ EntityReferenceSelection/ MediaSelection.php  - Creates a new entity object that can be used as a valid reference.
 - NodeSelection::createNewEntity in core/
modules/ node/ src/ Plugin/ EntityReferenceSelection/ NodeSelection.php  - Creates a new entity object that can be used as a valid reference.
 - TermSelection::createNewEntity in core/
modules/ taxonomy/ src/ Plugin/ EntityReferenceSelection/ TermSelection.php  - Creates a new entity object that can be used as a valid reference.
 
6 methods override DefaultSelection::createNewEntity()
- CommentSelection::createNewEntity in core/
modules/ comment/ src/ Plugin/ EntityReferenceSelection/ CommentSelection.php  - Creates a new entity object that can be used as a valid reference.
 - FileSelection::createNewEntity in core/
modules/ file/ src/ Plugin/ EntityReferenceSelection/ FileSelection.php  - Creates a new entity object that can be used as a valid reference.
 - MediaSelection::createNewEntity in core/
modules/ media/ src/ Plugin/ EntityReferenceSelection/ MediaSelection.php  - Creates a new entity object that can be used as a valid reference.
 - NodeSelection::createNewEntity in core/
modules/ node/ src/ Plugin/ EntityReferenceSelection/ NodeSelection.php  - Creates a new entity object that can be used as a valid reference.
 - TermSelection::createNewEntity in core/
modules/ taxonomy/ src/ Plugin/ EntityReferenceSelection/ TermSelection.php  - Creates a new entity object that can be used as a valid reference.
 
File
- 
              core/
lib/ Drupal/ Core/ Entity/ Plugin/ EntityReferenceSelection/ DefaultSelection.php, line 391  
Class
- DefaultSelection
 - Default plugin implementation of the Entity Reference Selection plugin.
 
Namespace
Drupal\Core\Entity\Plugin\EntityReferenceSelectionCode
public function createNewEntity($entity_type_id, $bundle, $label, $uid) {
  $entity_type = $this->entityTypeManager
    ->getDefinition($entity_type_id);
  $values = [
    $entity_type->getKey('label') => $label,
  ];
  if ($bundle_key = $entity_type->getKey('bundle')) {
    $values[$bundle_key] = $bundle;
  }
  $entity = $this->entityTypeManager
    ->getStorage($entity_type_id)
    ->create($values);
  if ($entity instanceof EntityOwnerInterface) {
    $entity->setOwnerId($uid);
  }
  return $entity;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.