social_post.install in Open Social 8.2
Same filename and directory in other branches
- 8.9 modules/social_features/social_post/social_post.install
- 8 modules/social_features/social_post/social_post.install
- 8.3 modules/social_features/social_post/social_post.install
- 8.4 modules/social_features/social_post/social_post.install
- 8.5 modules/social_features/social_post/social_post.install
- 8.6 modules/social_features/social_post/social_post.install
- 8.7 modules/social_features/social_post/social_post.install
- 8.8 modules/social_features/social_post/social_post.install
- 10.3.x modules/social_features/social_post/social_post.install
- 10.0.x modules/social_features/social_post/social_post.install
- 10.1.x modules/social_features/social_post/social_post.install
- 10.2.x modules/social_features/social_post/social_post.install
Install, update and uninstall functions for the social_comment module.
File
modules/social_features/social_post/social_post.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the social_comment module.
*/
use Drupal\user\Entity\Role;
/**
* PROCEED WITH CARE HERE!
*
* The below issue causes updates from the social_post module to be recognizes
* as post updates from the social profile.
*
* Therefore don't create update hooks here!!!!
*
* https://www.drupal.org/node/2880361
*/
/**
* Implements hook_install().
*
* Perform actions related to the installation of social_post.
*/
function social_post_install() {
// Set some default permissions.
_social_post_set_permissions();
}
/**
* Function to set permissions.
*/
function _social_post_set_permissions() {
$roles = Role::loadMultiple();
/** @var \Drupal\user\Entity\Role $role */
foreach ($roles as $role) {
if ($role
->id() === 'administrator') {
continue;
}
$permissions = _social_post_get_permissions($role
->id());
user_role_grant_permissions($role
->id(), $permissions);
}
}
/**
* Return the permissions per role.
*
* @param string $role
* The role to get the permissions for.
*
* @return array
* A list of permissions.
*/
function _social_post_get_permissions($role) {
// Anonymous.
$permissions['anonymous'] = [
'view public posts',
'view published post entities',
];
// Authenticated.
$permissions['authenticated'] = array_merge($permissions['anonymous'], [
'add post entities',
'delete own post entities',
'edit own post entities',
'view community posts',
'view own unpublished post entities',
]);
// Content manager.
$permissions['contentmanager'] = array_merge($permissions['authenticated'], [
'delete any post entities',
'edit any post entities',
'view unpublished post entities',
]);
// Site manager.
$permissions['sitemanager'] = array_merge($permissions['contentmanager'], []);
if (isset($permissions[$role])) {
return $permissions[$role];
}
return [];
}
Functions
Name | Description |
---|---|
social_post_install | Implements hook_install(). |
_social_post_get_permissions | Return the permissions per role. |
_social_post_set_permissions | Function to set permissions. |