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

Breadcrumb

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

function Role::onDependencyRemoval

Overrides ConfigEntityBase::onDependencyRemoval

File

core/modules/user/src/Entity/Role.php, line 236

Class

Role
Defines the user role entity class.

Namespace

Drupal\user\Entity

Code

public function onDependencyRemoval(array $dependencies) {
    $changed = parent::onDependencyRemoval($dependencies);
    // Load all permission definitions.
    $permission_definitions = \Drupal::service('user.permissions')->getPermissions();
    // Convert config and content entity dependencies to a list of names to make
    // it easier to check.
    foreach ([
        'content',
        'config',
    ] as $type) {
        $dependencies[$type] = array_keys($dependencies[$type]);
    }
    // Remove any permissions from the role that are dependent on anything being
    // deleted or uninstalled.
    foreach ($this->permissions as $key => $permission) {
        if (!isset($permission_definitions[$permission])) {
            // If the permission is not defined then there's nothing we can do.
            continue;
        }
        if (in_array($permission_definitions[$permission]['provider'], $dependencies['module'], TRUE)) {
            unset($this->permissions[$key]);
            $changed = TRUE;
            // Process the next permission.
            continue;
        }
        if (isset($permission_definitions[$permission]['dependencies'])) {
            foreach ($permission_definitions[$permission]['dependencies'] as $type => $list) {
                if (array_intersect($list, $dependencies[$type])) {
                    unset($this->permissions[$key]);
                    $changed = TRUE;
                    // Process the next permission.
                    continue 2;
                }
            }
        }
    }
    return $changed;
}

API Navigation

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