social_book.install in Open Social 8.9
Same filename and directory in other branches
- 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.7 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\Core\Entity\EntityStorageException;
use Drupal\search_api\Entity\Index;
use Drupal\user\Entity\Role;
use Symfony\Component\Yaml\Yaml;
/**
* Implements hook_install().
*
* Perform actions related to the installation of social_book.
*/
function social_book_install() {
// Set some default permissions.
_social_book_set_permissions();
}
/**
* Implements hook_update_dependencies().
*/
function social_book_update_dependencies() {
// Run the config update after the final features removal ran.
$dependencies['social_book'][8801] = [
'social_core' => 8802,
];
// Ensure update helper dependant hooks run after update helper
// is enabled.
$dependencies['social_book'][8802] = [
'social_core' => 8805,
];
return $dependencies;
}
/**
* 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);
}
}
}
/**
* Config import social_book default configs.
*
* The feature removal script did not succeed for social_book.
* Import the configs in an update hook.
*/
function social_book_update_8801() {
$config_files = [
'core.base_field_override.node.book.promote',
'core.entity_form_display.node.book.default',
'core.entity_view_display.node.book.activity_comment',
'core.entity_view_display.node.book.activity',
'core.entity_view_display.node.book.default',
'core.entity_view_display.node.book.hero',
'core.entity_view_display.node.book.search_index',
'core.entity_view_display.node.book.teaser',
];
foreach ($config_files as $config_file) {
$config = drupal_get_path('module', 'social_book') . '/config/features_removal/' . $config_file . '.yml';
if (is_file($config)) {
$settings = Yaml::parse(file_get_contents($config));
if (is_array($settings)) {
$update_config = \Drupal::configFactory()
->getEditable($config_file);
$update_config
->setData($settings)
->save(TRUE);
}
}
}
}
/**
* Hide image label in teasers.
*/
function social_book_update_8802() {
/** @var \Drupal\update_helper\Updater $updateHelper */
$updateHelper = \Drupal::service('update_helper.updater');
// Execute configuration update definitions with logging of success.
$updateHelper
->executeUpdate('social_book', 'social_book_update_8802');
// Output logged messages to related channel of update execution.
return $updateHelper
->logger()
->output();
}
/**
* Update search all with book pages.
*/
function social_book_update_8803() {
// If the search module is enabled trigger updating of the indexes affected
// by the book update in config override.
try {
$index = Index::load('social_all');
if ($index !== NULL && $index
->status()) {
$index
->save();
$index
->clear();
$index
->reindex();
}
} catch (EntityStorageException $e) {
\Drupal::logger('social_book')
->info($e
->getMessage());
}
}
/**
* Hide image label in hero.
*/
function social_book_update_8804() {
/** @var \Drupal\update_helper\Updater $updateHelper */
$updateHelper = \Drupal::service('update_helper.updater');
// Execute configuration update definitions with logging of success.
$updateHelper
->executeUpdate('social_book', 'social_book_update_8804');
// Output logged messages to related channel of update execution.
return $updateHelper
->logger()
->output();
}
Functions
Name | Description |
---|---|
social_book_install | Implements hook_install(). |
social_book_update_8001 | Enable book page creation permissions for CM and SM. |
social_book_update_8801 | Config import social_book default configs. |
social_book_update_8802 | Hide image label in teasers. |
social_book_update_8803 | Update search all with book pages. |
social_book_update_8804 | Hide image label in hero. |
social_book_update_dependencies | Implements hook_update_dependencies(). |
_social_book_get_permissions | Build the permissions. |
_social_book_set_permissions | Function to set permissions. |