function DefaultSelection::createNewEntity
Same name in other branches
- 8.9.x core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::createNewEntity()
- 10 core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::createNewEntity()
- 11.x core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::createNewEntity()
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.