function Role::preSave
Same name in other branches
- 9 core/modules/user/src/Entity/Role.php \Drupal\user\Entity\Role::preSave()
- 8.9.x core/modules/user/src/Entity/Role.php \Drupal\user\Entity\Role::preSave()
- 10 core/modules/user/src/Entity/Role.php \Drupal\user\Entity\Role::preSave()
Overrides ConfigEntityBase::preSave
File
-
core/
modules/ user/ src/ Entity/ Role.php, line 181
Class
- Role
- Defines the user role entity class.
Namespace
Drupal\user\EntityCode
public function preSave(EntityStorageInterface $storage) {
parent::preSave($storage);
if (!isset($this->weight)) {
// Set a role weight to make this new role last.
$this->weight = array_reduce($storage->loadMultiple(), function ($max, $role) {
return $max > $role->weight ? $max : $role->weight + 1;
}, 0);
}
if (!$this->isSyncing() && $this->hasTrustedData()) {
// Permissions are always ordered alphabetically to avoid conflicts in the
// exported configuration. If the save is not trusted then the
// configuration will be sorted by StorableConfigBase.
sort($this->permissions);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.