social_book.install in Open Social 8.7
Same filename and directory in other branches
- 8.9 modules/social_features/social_book/social_book.install
- 8 modules/social_features/social_book/social_book.install
- 8.2 modules/social_features/social_book/social_book.install
- 8.3 modules/social_features/social_book/social_book.install
- 8.4 modules/social_features/social_book/social_book.install
- 8.5 modules/social_features/social_book/social_book.install
- 8.6 modules/social_features/social_book/social_book.install
- 8.8 modules/social_features/social_book/social_book.install
- 10.3.x modules/social_features/social_book/social_book.install
- 10.0.x modules/social_features/social_book/social_book.install
- 10.1.x modules/social_features/social_book/social_book.install
- 10.2.x modules/social_features/social_book/social_book.install
Install, update and uninstall functions for the social_book module.
File
modules/social_features/social_book/social_book.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the social_book module.
*/
use Drupal\user\Entity\Role;
/**
* Implements hook_install().
*
* Perform actions related to the installation of social_book.
*/
function social_book_install() {
// Set some default permissions.
_social_book_set_permissions();
}
/**
* Function to set permissions.
*/
function _social_book_set_permissions() {
$roles = Role::loadMultiple();
/** @var \Drupal\user\Entity\Role $role */
foreach ($roles as $role) {
if ($role
->id() === 'administrator') {
continue;
}
$permissions = _social_book_get_permissions($role
->id());
user_role_grant_permissions($role
->id(), $permissions);
}
}
/**
* Build the permissions.
*
* @param string $role
* The role.
*
* @return array
* Returns an array containing the permissions.
*/
function _social_book_get_permissions($role) {
// Anonymous.
$permissions['anonymous'] = [
'view node.book.field_content_visibility:public content',
];
// Authenticated.
$permissions['authenticated'] = array_merge($permissions['anonymous'], [
'view node.book.field_content_visibility:community content',
]);
// Content manager.
$permissions['contentmanager'] = array_merge($permissions['authenticated'], [
'create new books',
'add content to books',
'create book content',
'delete any book content',
'delete own book content',
'delete book revisions',
'revert book revisions',
'edit any book content',
'edit own book content',
'view book revisions',
]);
// Site manager.
$permissions['sitemanager'] = array_merge($permissions['contentmanager'], [
'administer visibility settings',
]);
if (isset($permissions[$role])) {
return $permissions[$role];
}
return [];
}
/**
* Enable book page creation permissions for CM and SM.
*/
function social_book_update_8001() {
$roles = Role::loadMultiple();
$permissions = [
'create new books',
'add content to books',
'create book content',
'delete any book content',
'delete own book content',
'delete book revisions',
'revert book revisions',
'edit any book content',
'edit own book content',
'view book revisions',
];
/** @var \Drupal\user\Entity\Role $role */
foreach ($roles as $role) {
if ($role
->id() === 'contentmanager' || $role
->id() === 'sitemanager') {
user_role_grant_permissions($role
->id(), $permissions);
}
}
}
Functions
Name | Description |
---|---|
social_book_install | Implements hook_install(). |
social_book_update_8001 | Enable book page creation permissions for CM and SM. |
_social_book_get_permissions | Build the permissions. |
_social_book_set_permissions | Function to set permissions. |