You are here

protected function PermissionConfigurationHandler::buildCache in Configuration Management 7.3

1 call to PermissionConfigurationHandler::buildCache()
PermissionConfigurationHandler::__construct in src/Handlers/PermissionConfigurationHandler.php

File

src/Handlers/PermissionConfigurationHandler.php, line 32

Class

PermissionConfigurationHandler

Namespace

Configuration\Handlers

Code

protected function buildCache() {
  $this->roles_names = array(
    DRUPAL_ANONYMOUS_RID => 'anonymous_user',
    DRUPAL_AUTHENTICATED_RID => 'authenticated_user',
  );
  $this->roles_ids = array(
    'anonymous_user' => DRUPAL_ANONYMOUS_RID,
    'authenticated_user' => DRUPAL_AUTHENTICATED_RID,
  );
  foreach ($this->configuration_manager
    ->drupal()
    ->role_export_roles() as $role) {
    if ($role->rid > 2) {
      $this->roles_ids[$role->machine_name] = $role->rid;
      $this->roles_names[$role->rid] = $role->machine_name;
    }
  }
  $this->cached_permissions = array();
  foreach ($this->cached_permissions_modules as $permission => $module) {
    $id = preg_replace("/[^a-zA-Z0-9]+/", "_", $permission);
    $this->cached_permissions[$id] = array(
      'permission' => $permission,
      'module' => $module,
      'roles' => array(),
    );
  }
  foreach ($this->configuration_manager
    ->drupal()
    ->user_role_permissions($this->roles_names) as $rid => $role_permissions) {
    foreach (array_keys($role_permissions) as $permission) {
      $id = preg_replace("/[^a-zA-Z0-9]+/", "_", $permission);
      if (isset($this->cached_permissions_modules[$permission])) {
        $this->cached_permissions[$id]['roles'][] = $this->roles_names[$rid];
      }
    }
  }
}