public function UserSelection::createNewEntity in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php \Drupal\user\Plugin\EntityReferenceSelection\UserSelection::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/ user/ src/ Plugin/ EntityReferenceSelection/ UserSelection.php, line 174 - Contains \Drupal\user\Plugin\EntityReferenceSelection\UserSelection.
Class
- UserSelection
- Provides specific access control for the user entity type.
Namespace
Drupal\user\Plugin\EntityReferenceSelectionCode
public function createNewEntity($entity_type_id, $bundle, $label, $uid) {
$user = parent::createNewEntity($entity_type_id, $bundle, $label, $uid);
// In order to create a referenceable user, it needs to be active.
if (!$this->currentUser
->hasPermission('administer users')) {
/** @var \Drupal\user\UserInterface $user */
$user
->activate();
}
return $user;
}