group_core_comments.install in Open Social 10.1.x
Same filename and directory in other branches
- 8.9 modules/custom/group_core_comments/group_core_comments.install
- 8 modules/custom/group_core_comments/group_core_comments.install
- 8.2 modules/custom/group_core_comments/group_core_comments.install
- 8.3 modules/custom/group_core_comments/group_core_comments.install
- 8.4 modules/custom/group_core_comments/group_core_comments.install
- 8.5 modules/custom/group_core_comments/group_core_comments.install
- 8.6 modules/custom/group_core_comments/group_core_comments.install
- 8.7 modules/custom/group_core_comments/group_core_comments.install
- 8.8 modules/custom/group_core_comments/group_core_comments.install
- 10.3.x modules/custom/group_core_comments/group_core_comments.install
- 10.0.x modules/custom/group_core_comments/group_core_comments.install
- 10.2.x modules/custom/group_core_comments/group_core_comments.install
Install, update and uninstall functions for the group_core_comments module.
File
modules/custom/group_core_comments/group_core_comments.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the group_core_comments module.
*/
use Drupal\user\Entity\Role;
/**
* Implements hook_install().
*
* Perform actions related to the installation of group_core_comments.
*/
function group_core_comments_install() {
// Set some default permissions.
_group_core_comments_set_permissions();
}
/**
* Function to set permissions.
*/
function _group_core_comments_set_permissions() {
$roles = Role::loadMultiple();
/** @var \Drupal\user\Entity\Role $role */
foreach ($roles as $role) {
if ($role
->id() === 'administrator') {
continue;
}
$permissions = _group_core_comments_get_permissions($role
->id());
user_role_grant_permissions($role
->id(), $permissions);
}
}
/**
* Get permissions per role.
*
* @param string $role
* The name of the role.
*
* @return array
* A list of permissions.
*/
function _group_core_comments_get_permissions($role) {
// Anonymous.
$permissions['anonymous'] = [];
// Authenticated.
$permissions['authenticated'] = array_merge($permissions['anonymous'], []);
// Content manager.
$permissions['contentmanager'] = array_merge($permissions['authenticated'], []);
// Site manager.
$permissions['sitemanager'] = array_merge($permissions['contentmanager'], [
'delete all comments',
]);
if (isset($permissions[$role])) {
return $permissions[$role];
}
return [];
}
/**
* Enable 'delete all comments' permission for site manager users.
*/
function group_core_comments_update_8001(&$sandbox) {
$roles = Role::loadMultiple();
$permissions = [
'delete all comments',
];
/** @var \Drupal\user\Entity\Role $role */
foreach ($roles as $role) {
if ($role
->id() === 'sitemanager') {
user_role_grant_permissions($role
->id(), $permissions);
}
}
}
Functions
Name![]() |
Description |
---|---|
group_core_comments_install | Implements hook_install(). |
group_core_comments_update_8001 | Enable 'delete all comments' permission for site manager users. |
_group_core_comments_get_permissions | Get permissions per role. |
_group_core_comments_set_permissions | Function to set permissions. |