function UserSelection::validateReferenceableNewEntities
Same name in other branches
- 9 core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php \Drupal\user\Plugin\EntityReferenceSelection\UserSelection::validateReferenceableNewEntities()
- 8.9.x core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php \Drupal\user\Plugin\EntityReferenceSelection\UserSelection::validateReferenceableNewEntities()
- 11.x core/modules/user/src/Plugin/EntityReferenceSelection/UserSelection.php \Drupal\user\Plugin\EntityReferenceSelection\UserSelection::validateReferenceableNewEntities()
Overrides DefaultSelection::validateReferenceableNewEntities
File
-
core/
modules/ user/ src/ Plugin/ EntityReferenceSelection/ UserSelection.php, line 204
Class
- UserSelection
- Provides specific access control for the user entity type.
Namespace
Drupal\user\Plugin\EntityReferenceSelectionCode
public function validateReferenceableNewEntities(array $entities) {
$entities = parent::validateReferenceableNewEntities($entities);
// Mirror the conditions checked in buildEntityQuery().
if ($role = $this->getConfiguration()['filter']['role']) {
$entities = array_filter($entities, function ($user) use ($role) {
/** @var \Drupal\user\UserInterface $user */
return !empty(array_intersect($user->getRoles(), $role));
});
}
if (!$this->currentUser
->hasPermission('administer users')) {
$entities = array_filter($entities, function ($user) {
/** @var \Drupal\user\UserInterface $user */
return $user->isActive();
});
}
return $entities;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.