social_tour.install in Open Social 10.0.x
Same filename and directory in other branches
- 8.9 modules/custom/social_tour/social_tour.install
- 8 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.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 ($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. |