function UserSelection::createNewEntity

Same name in other branches
  1. 8.9.x core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php \Drupal\user\Plugin\EntityReferenceSelection\UserSelection::createNewEntity()
  2. 10 core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php \Drupal\user\Plugin\EntityReferenceSelection\UserSelection::createNewEntity()
  3. 11.x core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php \Drupal\user\Plugin\EntityReferenceSelection\UserSelection::createNewEntity()

Overrides DefaultSelection::createNewEntity

File

core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php, line 180

Class

UserSelection
Provides specific access control for the user entity type.

Namespace

Drupal\user\Plugin\EntityReferenceSelection

Code

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.