Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Role.php

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\Entity

Code

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

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal