social_profile_privacy.install in Open Social 8.8
Same filename and directory in other branches
- 8.9 modules/social_features/social_profile/modules/social_profile_privacy/social_profile_privacy.install
- 8 modules/social_features/social_profile/modules/social_profile_privacy/social_profile_privacy.install
- 8.2 modules/social_features/social_profile/modules/social_profile_privacy/social_profile_privacy.install
- 8.3 modules/social_features/social_profile/modules/social_profile_privacy/social_profile_privacy.install
- 8.4 modules/social_features/social_profile/modules/social_profile_privacy/social_profile_privacy.install
- 8.5 modules/social_features/social_profile/modules/social_profile_privacy/social_profile_privacy.install
- 8.6 modules/social_features/social_profile/modules/social_profile_privacy/social_profile_privacy.install
- 8.7 modules/social_features/social_profile/modules/social_profile_privacy/social_profile_privacy.install
- 10.3.x modules/social_features/social_profile/modules/social_profile_privacy/social_profile_privacy.install
- 10.0.x modules/social_features/social_profile/modules/social_profile_privacy/social_profile_privacy.install
- 10.1.x modules/social_features/social_profile/modules/social_profile_privacy/social_profile_privacy.install
- 10.2.x modules/social_features/social_profile/modules/social_profile_privacy/social_profile_privacy.install
The social profile privacy install file.
File
modules/social_features/social_profile/modules/social_profile_privacy/social_profile_privacy.installView source
<?php
/**
* @file
* The social profile privacy install file.
*/
use Drupal\user\Entity\Role;
/**
* Implements hook_install().
*/
function social_profile_privacy_install() {
// Set some default permissions.
_social_profile_privacy_set_permissions();
// Update our search indexes for our custom processor..
_social_profile_privacy_resave_search_indexes();
}
/**
* Function to set permissions.
*/
function _social_profile_privacy_set_permissions() {
$roles = Role::loadMultiple();
/** @var \Drupal\user\Entity\Role $role */
foreach ($roles as $role) {
$permissions = _social_profile_privacy_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_profile_privacy_get_permissions($role) {
// Anonymous.
$permissions['anonymous'] = [];
// Authenticated.
$permissions['authenticated'] = array_merge($permissions['anonymous'], []);
// Content manager.
$permissions['contentmanager'] = array_merge($permissions['authenticated'], []);
// Site manager.
$permissions['sitemanager'] = array_merge($permissions['contentmanager'], [
'social profile privacy view hidden fields',
]);
// If the requested role is not defined we return no permissions.
// Drupal will make them inherit the authenticated user permissions.
if (!isset($permissions[$role])) {
return [];
}
return $permissions[$role];
}
Functions
Name | Description |
---|---|
social_profile_privacy_install | Implements hook_install(). |
_social_profile_privacy_get_permissions | Return the permissions per role. |
_social_profile_privacy_set_permissions | Function to set permissions. |