social_mentions.install in Open Social 8.3
Same filename and directory in other branches
- 8.9 modules/social_features/social_mentions/social_mentions.install
- 8 modules/social_features/social_mentions/social_mentions.install
- 8.2 modules/social_features/social_mentions/social_mentions.install
- 8.4 modules/social_features/social_mentions/social_mentions.install
- 8.5 modules/social_features/social_mentions/social_mentions.install
- 8.6 modules/social_features/social_mentions/social_mentions.install
- 8.7 modules/social_features/social_mentions/social_mentions.install
- 8.8 modules/social_features/social_mentions/social_mentions.install
- 10.3.x modules/social_features/social_mentions/social_mentions.install
- 10.0.x modules/social_features/social_mentions/social_mentions.install
- 10.1.x modules/social_features/social_mentions/social_mentions.install
- 10.2.x modules/social_features/social_mentions/social_mentions.install
Install, update and uninstall functions for the social_mentions module.
File
modules/social_features/social_mentions/social_mentions.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the social_mentions module.
*/
use Drupal\user\Entity\Role;
/**
* Implements hook_install().
*
* Perform actions related to the installation of social_mentions.
*/
function social_mentions_install() {
// Set some default permissions.
_social_mentions_set_permissions();
// Set default configurations.
_social_mentions_set_default_config();
}
/**
* Set suggestion amount to the default of 8.
*/
function social_mentions_update_8001() {
$config = \Drupal::configFactory()
->getEditable('mentions.settings');
$config
->set('suggestions_amount', 8);
$config
->save();
}
/**
* Function to set permissions.
*/
function _social_mentions_set_permissions() {
$roles = Role::loadMultiple();
/** @var \Drupal\user\Entity\Role $role */
foreach ($roles as $role) {
if ($role
->id() === 'administrator') {
continue;
}
$permissions = _social_mentions_get_permissions($role
->id());
user_role_grant_permissions($role
->id(), $permissions);
}
}
/**
* Build the permissions.
*/
function _social_mentions_get_permissions($role) {
// Anonymous.
$permissions['anonymous'] = [];
// Authenticated.
$permissions['authenticated'] = array_merge($permissions['anonymous'], [
'access mentions',
]);
// 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 default settings.
*/
function _social_mentions_set_default_config() {
$config = \Drupal::configFactory()
->getEditable('mentions.settings');
$allowed_entity_types = [
'post',
'comment',
];
$allowed_entity_types = array_combine($allowed_entity_types, $allowed_entity_types);
$config
->set('supported_entity_types', $allowed_entity_types);
$config
->set('suggestions_format', SOCIAL_PROFILE_SUGGESTIONS_ALL);
$config
->set('suggestions_amount', 8);
$config
->save();
}
Functions
Name | Description |
---|---|
social_mentions_install | Implements hook_install(). |
social_mentions_update_8001 | Set suggestion amount to the default of 8. |
_social_mentions_get_permissions | Build the permissions. |
_social_mentions_set_default_config | Set default settings. |
_social_mentions_set_permissions | Function to set permissions. |