social_like.install in Open Social 8
Same filename and directory in other branches
- 8.9 modules/social_features/social_like/social_like.install
- 8.2 modules/social_features/social_like/social_like.install
- 8.3 modules/social_features/social_like/social_like.install
- 8.4 modules/social_features/social_like/social_like.install
- 8.5 modules/social_features/social_like/social_like.install
- 8.6 modules/social_features/social_like/social_like.install
- 8.7 modules/social_features/social_like/social_like.install
- 8.8 modules/social_features/social_like/social_like.install
- 10.3.x modules/social_features/social_like/social_like.install
- 10.0.x modules/social_features/social_like/social_like.install
- 10.1.x modules/social_features/social_like/social_like.install
- 10.2.x modules/social_features/social_like/social_like.install
Install, update and uninstall functions for the social_like module.
File
modules/social_features/social_like/social_like.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the social_like module.
*/
use Drupal\user\Entity\Role;
/**
* Implements hook_install().
*
* Perform actions related to the installation of social_like.
*/
function social_like_install() {
// Set some default permissions.
_social_like_set_permissions();
}
/**
* Re-set permissions for viewing the like widget.
*/
function social_like_update_8001() {
// Set some default permissions.
_social_like_set_permissions();
}
/**
* Re-set permissions for viewing the like widget.
*/
function social_like_update_8002() {
// Revoke permission for AN like widget.
user_role_revoke_permissions('anonymous', [
'view like widget',
]);
}
/**
* Disable bootstrap modal.
*/
function social_like_update_8003() {
// Bootstrap modal breaks jquery.dialog, so turn it off.
$settings = \Drupal::configFactory()
->getEditable('socialbase.settings');
$settings
->set('modal_enabled', 0)
->save();
}
/**
* Install views_infinite_scroll module.
*/
function social_like_update_8004() {
$modules = [
'views_infinite_scroll',
];
\Drupal::service('module_installer')
->install($modules);
}
/**
* Enable deleting likes from a database when a user is deleted.
*/
function social_like_update_8005() {
\Drupal::configFactory()
->getEditable('votingapi.settings')
->set('delete_everywhere', TRUE)
->save();
}
/**
* Function to set permissions.
*/
function _social_like_set_permissions() {
$roles = Role::loadMultiple();
/** @var \Drupal\user\Entity\Role $role */
foreach ($roles as $role) {
if ($role
->id() === 'administrator') {
continue;
}
$permissions = _social_like_get_permissions($role
->id());
user_role_grant_permissions($role
->id(), $permissions);
}
}
/**
* Build the permissions.
*/
function _social_like_get_permissions($role) {
// Anonymous.
$permissions['anonymous'] = [
'view like widget',
];
// Authenticated.
$permissions['authenticated'] = array_merge($permissions['anonymous'], [
'add or remove like votes on post',
'add or remove like votes on comment of comment',
'add or remove like votes on post_comment of comment',
'add or remove like votes on topic of node',
'add or remove like votes on event of node',
]);
// Content manager.
$permissions['contentmanager'] = array_merge($permissions['authenticated'], []);
// Site manager.
$permissions['sitemanager'] = array_merge($permissions['contentmanager'], []);
if (isset($permissions[$role])) {
return $permissions[$role];
}
return [];
}
Functions
Name | Description |
---|---|
social_like_install | Implements hook_install(). |
social_like_update_8001 | Re-set permissions for viewing the like widget. |
social_like_update_8002 | Re-set permissions for viewing the like widget. |
social_like_update_8003 | Disable bootstrap modal. |
social_like_update_8004 | Install views_infinite_scroll module. |
social_like_update_8005 | Enable deleting likes from a database when a user is deleted. |
_social_like_get_permissions | Build the permissions. |
_social_like_set_permissions | Function to set permissions. |