class RoleStorageController

Controller class for user roles.

Hierarchy

Expanded class hierarchy of RoleStorageController

File

drupal/core/modules/user/lib/Drupal/user/RoleStorageController.php, line 16
Contains \Drupal\user\RoleStorageController.

Namespace

Drupal\user
View source
class RoleStorageController extends ConfigStorageController {

  /**
   * {@inheritdoc}
   */
  public function preSave(EntityInterface $entity) {
    if (!isset($entity->weight) && ($roles = entity_load_multiple('user_role'))) {

      // Set a role weight to make this new role last.
      $max = array_reduce($roles, function ($max, $entity) {
        return $max > $entity->weight ? $max : $entity->weight;
      });
      $entity->weight = $max + 1;
    }
    parent::preSave($entity);
  }

  /**
   * {@inheritdoc}
   */
  public function resetCache(array $ids = NULL) {
    parent::resetCache($ids);

    // Clear the user access cache.
    drupal_static_reset('user_access');
    drupal_static_reset('user_role_permissions');
  }

  /**
   * {@inheritdoc}
   */
  protected function postDelete($entities) {
    $rids = array_keys($entities);

    // Delete permission assignments.
    db_delete('role_permission')
      ->condition('rid', $rids)
      ->execute();

    // Remove the role from all users.
    db_delete('users_roles')
      ->condition('rid', $rids)
      ->execute();
  }

  /**
   * {@inheritdoc}
   */
  protected function attachLoad(&$queried_entities, $revision_id = FALSE) {

    // Sort the queried roles by their weight.
    uasort($queried_entities, 'Drupal\\Core\\Config\\Entity\\ConfigEntityBase::sort');
    parent::attachLoad($queried_entities, $revision_id);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigStorageController::$configFactory protected property The config factory service.
ConfigStorageController::$configStorage protected property The config storage service.
ConfigStorageController::$statusKey protected property Name of the entity's status key or FALSE if a status is not supported.
ConfigStorageController::$uuidKey protected property Name of the entity's UUID property. Overrides EntityStorageControllerBase::$uuidKey
ConfigStorageController::buildQuery protected function Builds the query to load the entity.
ConfigStorageController::create public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::create(). Overrides EntityStorageControllerInterface::create 2
ConfigStorageController::createInstance public static function Instantiates a new instance of this entity controller. Overrides EntityControllerInterface::createInstance 2
ConfigStorageController::delete public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::delete(). Overrides EntityStorageControllerInterface::delete
ConfigStorageController::deleteRevision public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::deleteRevision(). Overrides EntityStorageControllerInterface::deleteRevision
ConfigStorageController::getConfigPrefix public function Returns the config prefix used by the configuration entity type.
ConfigStorageController::getFieldDefinitions public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::getFieldDefinitions(). Overrides EntityStorageControllerInterface::getFieldDefinitions
ConfigStorageController::getIDFromConfigName public static function Extracts the configuration entity ID from the full configuration name.
ConfigStorageController::getQueryServicename public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::getQueryServicename(). Overrides EntityStorageControllerInterface::getQueryServicename
ConfigStorageController::importCreate public function Create configuration upon synchronizing configuration changes. 1
ConfigStorageController::importDelete public function Delete configuration upon synchronizing configuration changes. 2
ConfigStorageController::importUpdate public function Updates configuration upon synchronizing configuration changes. 1
ConfigStorageController::invokeHook protected function Invokes a hook on behalf of the entity.
ConfigStorageController::load public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::load(). Overrides EntityStorageControllerInterface::load 2
ConfigStorageController::loadByProperties public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::loadByProperties(). Overrides EntityStorageControllerInterface::loadByProperties 2
ConfigStorageController::loadRevision public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::loadRevision(). Overrides EntityStorageControllerInterface::loadRevision
ConfigStorageController::postSave protected function Acts on a saved entity before the insert or update hook is invoked. 7
ConfigStorageController::preDelete protected function Acts on entities before they are deleted. 3
ConfigStorageController::save public function Implements Drupal\Core\Entity\EntityStorageControllerInterface::save(). Overrides EntityStorageControllerInterface::save
ConfigStorageController::__construct public function Constructs a ConfigStorageController object. Overrides EntityStorageControllerBase::__construct 2
EntityStorageControllerBase::$cache protected property Whether this entity type should use the static cache. 1
EntityStorageControllerBase::$entityCache protected property Static cache of entities.
EntityStorageControllerBase::$entityInfo protected property Array of information about the entity.
EntityStorageControllerBase::$entityType protected property Entity type for this controller instance.
EntityStorageControllerBase::$hookLoadArguments protected property Additional arguments to pass to hook_TYPE_load().
EntityStorageControllerBase::$idKey protected property Name of the entity's ID field in the entity database table.
EntityStorageControllerBase::cacheGet protected function Gets entities from the static cache.
EntityStorageControllerBase::cacheSet protected function Stores entities in the static entity cache.
EntityStorageControllerBase::loadUnchanged public function Loads an unchanged entity from the database. Overrides EntityStorageControllerInterface::loadUnchanged
RoleStorageController::attachLoad protected function Attaches data to entities upon loading. Overrides ConfigStorageController::attachLoad
RoleStorageController::postDelete protected function Acts on deleted entities before the delete hook is invoked. Overrides ConfigStorageController::postDelete
RoleStorageController::preSave public function Acts on an entity before the presave hook is invoked. Overrides ConfigStorageController::preSave
RoleStorageController::resetCache public function Resets the internal, static entity cache. Overrides EntityStorageControllerBase::resetCache