You are here

function nodeaccess_entity_update in Nodeaccess 8.2

Same name and namespace in other branches
  1. 8 nodeaccess.module \nodeaccess_entity_update()

Implements hook_entity_update().

File

./nodeaccess.module, line 142
Control access to site content based on the users and roles.

Code

function nodeaccess_entity_update(EntityInterface $entity) {
  $config = \Drupal::configFactory()
    ->getEditable('nodeaccess.settings');
  if ($entity instanceof RoleInterface) {
    $role_alias = $config
      ->get('role_alias');
    if ($role_alias[$entity
      ->id()]) {
      $role_alias[$entity
        ->id()]['alias'] = $entity
        ->label();
      $role_alias[$entity
        ->id()]['name'] = $entity
        ->label();
    }
    else {
      $role_alias[$entity
        ->id()] = [
        'alias' => $entity
          ->label(),
        'name' => $entity
          ->label(),
        'weight' => 0,
        'allow' => 0,
      ];
    }
    $config
      ->set('role_alias', $role_alias);
    $config
      ->save();
  }
}