social_private_message.install in Open Social 8.6
Same filename and directory in other branches
- 8.9 modules/social_features/social_private_message/social_private_message.install
- 8 modules/social_features/social_private_message/social_private_message.install
- 8.2 modules/social_features/social_private_message/social_private_message.install
- 8.3 modules/social_features/social_private_message/social_private_message.install
- 8.4 modules/social_features/social_private_message/social_private_message.install
- 8.5 modules/social_features/social_private_message/social_private_message.install
- 8.7 modules/social_features/social_private_message/social_private_message.install
- 8.8 modules/social_features/social_private_message/social_private_message.install
- 10.3.x modules/social_features/social_private_message/social_private_message.install
- 10.0.x modules/social_features/social_private_message/social_private_message.install
- 10.1.x modules/social_features/social_private_message/social_private_message.install
- 10.2.x modules/social_features/social_private_message/social_private_message.install
The Social Private Message (de)installation file.
File
modules/social_features/social_private_message/social_private_message.installView source
<?php
/**
* @file
* The Social Private Message (de)installation file.
*/
use Drupal\user\Entity\Role;
/**
* Implements hook_uninstall().
*/
function social_private_message_install() {
_social_private_message_set_permissions();
// Disable the email notification provided by private_message.
/** @var \Drupal\Core\Config\Config|\Drupal\Core\Config\ImmutableConfig $config */
$config = \Drupal::getContainer()
->get('config.factory')
->getEditable('private_message.settings');
$config
->set('enable_email_notifications', FALSE)
->save();
$config
->set('send_by_default', FALSE)
->save();
// Set module weight.
module_set_weight('social_private_message', 1);
}
/**
* Function to set permissions.
*/
function _social_private_message_set_permissions() {
$roles = Role::loadMultiple();
/** @var \Drupal\user\Entity\Role $role */
foreach ($roles as $role) {
if ($role
->id() === 'administrator') {
continue;
}
$permissions = _social_private_message_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_private_message_get_permissions($role) {
// Anonymous.
$permissions['anonymous'] = [];
// Authenticated.
$permissions['authenticated'] = array_merge($permissions['anonymous'], [
'use private messaging system',
]);
// Content manager.
$permissions['contentmanager'] = array_merge($permissions['authenticated'], []);
// Site manager.
$permissions['sitemanager'] = array_merge($permissions['contentmanager'], []);
if (isset($permissions[$role])) {
return $permissions[$role];
}
return [];
}
/**
* Set module weight.
*/
function social_private_message_update_8001() {
module_set_weight('social_private_message', 1);
}
/**
* Remove inbox blocks.
*/
function social_private_message_update_8002() {
$plugin = 'social_private_message_inbox_block';
$storage = \Drupal::entityTypeManager()
->getStorage('block');
$blocks = $storage
->loadByProperties([
'plugin' => $plugin,
]);
/** @var \Drupal\block\Entity\Block $block */
foreach ($blocks as $block) {
$block
->delete();
}
}
Functions
Name | Description |
---|---|
social_private_message_install | Implements hook_uninstall(). |
social_private_message_update_8001 | Set module weight. |
social_private_message_update_8002 | Remove inbox blocks. |
_social_private_message_get_permissions | Build the permissions. |
_social_private_message_set_permissions | Function to set permissions. |