public function ContentRoleManager::grantPermissions in Lightning Core 8.4
Same name and namespace in other branches
- 8.5 modules/lightning_roles/src/ContentRoleManager.php \Drupal\lightning_roles\ContentRoleManager::grantPermissions()
- 8 modules/lightning_roles/src/ContentRoleManager.php \Drupal\lightning_roles\ContentRoleManager::grantPermissions()
- 8.2 modules/lightning_roles/src/ContentRoleManager.php \Drupal\lightning_roles\ContentRoleManager::grantPermissions()
- 8.3 modules/lightning_roles/src/ContentRoleManager.php \Drupal\lightning_roles\ContentRoleManager::grantPermissions()
Grants permissions (or meta-permissions) to a content role.
Parameters
string $role_id: The content role ID.
string[] $permissions: The permissions to grant. Can contain the '?' token, which will be replaced with the node type ID.
Return value
$this The called object, for chaining.
File
- modules/
lightning_roles/ src/ ContentRoleManager.php, line 52
Class
- ContentRoleManager
- A service for managing the configuration and deployment of content roles.
Namespace
Drupal\lightning_rolesCode
public function grantPermissions($role_id, array $permissions) {
$key = "content_roles.{$role_id}";
$config = $this->configFactory
->getEditable('lightning_roles.settings');
// Add the raw permissions to the content role.
$role = $config
->get($key);
$role['permissions'] = array_merge($role['permissions'], $permissions);
$config
->set($key, $role)
->save();
if ($role['enabled']) {
// Look up all node type IDs.
$node_types = $this->nodeTypeStorage
->getQuery()
->execute();
foreach ($node_types as $node_type) {
$permissions = str_replace('?', $node_type, $role['permissions']);
user_role_grant_permissions($node_type . '_' . $role_id, $permissions);
}
}
return $this;
}