public function DefaultSelection::createNewEntity in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Entity/Plugin/EntityReferenceSelection/DefaultSelection.php \Drupal\Core\Entity\Plugin\EntityReferenceSelection\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
4 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.
- NodeSelection::createNewEntity in core/
modules/ node/ src/ Plugin/ EntityReferenceSelection/ NodeSelection.php - Creates a new entity object that can be used as a valid reference.
- UserSelection::createNewEntity in core/
modules/ user/ src/ Plugin/ EntityReferenceSelection/ UserSelection.php - Creates a new entity object that can be used as a valid reference.
4 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.
- NodeSelection::createNewEntity in core/
modules/ node/ src/ Plugin/ EntityReferenceSelection/ NodeSelection.php - Creates a new entity object that can be used as a valid reference.
- UserSelection::createNewEntity in core/
modules/ user/ src/ Plugin/ EntityReferenceSelection/ UserSelection.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 296 - Contains \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection.
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->entityManager
->getDefinition($entity_type_id);
$bundle_key = $entity_type
->getKey('bundle');
$label_key = $entity_type
->getKey('label');
$entity = $this->entityManager
->getStorage($entity_type_id)
->create(array(
$bundle_key => $bundle,
$label_key => $label,
));
if ($entity instanceof EntityOwnerInterface) {
$entity
->setOwnerId($uid);
}
return $entity;
}