function nodeaccess_entity_insert in Nodeaccess 8
Same name and namespace in other branches
- 8.2 nodeaccess.module \nodeaccess_entity_insert()
Implements hook_entity_insert().
File
- ./
nodeaccess.module, line 168 - Control access to site content based on the users and roles.
Code
function nodeaccess_entity_insert(EntityInterface $entity) {
$config = \Drupal::configFactory()
->getEditable('nodeaccess.settings');
if ($entity instanceof RoleInterface) {
$roles_gids = array_flip($config
->get('role_map'));
$roles_gids[] = $entity
->id();
$config
->set('role_map', array_flip($roles_gids));
$role_alias = $config
->get('role_alias');
$role_alias[$entity
->id()] = [
'alias' => $entity
->label(),
'name' => $entity
->label(),
'weight' => 0,
'allow' => 0,
];
$config
->set('role_alias', $role_alias);
$config
->save();
}
}