function Role::preSave
Overrides ConfigEntityBase::preSave
File
-
core/
modules/ user/ src/ Entity/ Role.php, line 186
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);
}
}