social_tour.install in Open Social 8
Same filename and directory in other branches
- 8.9 modules/custom/social_tour/social_tour.install
- 8.2 modules/custom/social_tour/social_tour.install
- 8.3 modules/custom/social_tour/social_tour.install
- 8.4 modules/custom/social_tour/social_tour.install
- 8.5 modules/custom/social_tour/social_tour.install
- 8.6 modules/custom/social_tour/social_tour.install
- 8.7 modules/custom/social_tour/social_tour.install
- 8.8 modules/custom/social_tour/social_tour.install
- 10.3.x modules/custom/social_tour/social_tour.install
- 10.0.x modules/custom/social_tour/social_tour.install
- 10.1.x modules/custom/social_tour/social_tour.install
- 10.2.x modules/custom/social_tour/social_tour.install
Install, update and uninstall functions for the social_tour module.
File
modules/custom/social_tour/social_tour.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the social_tour module.
*/
use Drupal\user\Entity\Role;
/**
* Implements hook_install().
*
* Perform actions related to the installation of social_tour.
*/
function social_tour_install() {
// Set some default permissions.
_social_tour_set_permissions();
// Enable the module's on/off setting by default.
\Drupal::configFactory()
->getEditable('social_tour.settings')
->set('social_tour_enabled', 1)
->save();
}
/**
* Implements hook_uninstall().
*
* Remove config that was imported on install.
*/
function social_tour_uninstall() {
$configs = [
'tour.tour.social-event-overview',
'tour.tour.social-explore',
'tour.tour.social-group',
'tour.tour.social-group-overview',
'tour.tour.social-home',
'tour.tour.social-node-view',
'tour.tour.social-profile',
'tour.tour.social-topic-overview',
'tour.tour.social-user',
];
foreach ($configs as $config) {
// Deleting config.
\Drupal::configFactory()
->getEditable($config)
->delete();
}
}
/**
* Reinstall the tours, because of some textual changes.
*/
function social_tour_update_8001(&$sandbox) {
// Reinstall the tours, because of some textual changes.
social_tour_reimport_config();
}
/**
* Function to set permissions.
*/
function _social_tour_set_permissions() {
$roles = Role::loadMultiple();
/** @var \Drupal\user\Entity\Role $role */
foreach ($roles as $role) {
$permissions = _social_tour_get_permissions($role
->id());
if (!is_null($permissions)) {
user_role_grant_permissions($role
->id(), $permissions);
}
}
}
/**
* Build permissions.
*
* @param string $role
* The role.
*
* @return array
* Returns an array.
*/
function _social_tour_get_permissions($role) {
$permissions = [];
// Anonymous.
$permissions['anonymous'] = [];
// Authenticated.
$permissions['authenticated'] = array_merge($permissions['anonymous'], [
'access tour',
]);
// Content manager.
$permissions['contentmanager'] = array_merge($permissions['authenticated'], []);
// Site manager.
$permissions['sitemanager'] = array_merge($permissions['contentmanager'], [
'manage tour',
]);
if (isset($permissions[$role])) {
return $permissions[$role];
}
return [];
}
Functions
Name | Description |
---|---|
social_tour_install | Implements hook_install(). |
social_tour_uninstall | Implements hook_uninstall(). |
social_tour_update_8001 | Reinstall the tours, because of some textual changes. |
_social_tour_get_permissions | Build permissions. |
_social_tour_set_permissions | Function to set permissions. |