social_font.install in Open Social 8
Same filename and directory in other branches
- 8.9 modules/custom/social_font/social_font.install
- 8.2 modules/custom/social_font/social_font.install
- 8.3 modules/custom/social_font/social_font.install
- 8.4 modules/custom/social_font/social_font.install
- 8.5 modules/custom/social_font/social_font.install
- 8.6 modules/custom/social_font/social_font.install
- 8.7 modules/custom/social_font/social_font.install
- 8.8 modules/custom/social_font/social_font.install
- 10.3.x modules/custom/social_font/social_font.install
- 10.0.x modules/custom/social_font/social_font.install
- 10.1.x modules/custom/social_font/social_font.install
- 10.2.x modules/custom/social_font/social_font.install
Contains social_font.install.
File
modules/custom/social_font/social_font.installView source
<?php
/**
* @file
* Contains social_font.install.
*/
use Drupal\social_font\Entity\Font;
use Drupal\user\Entity\Role;
/**
* The social_font install file.
*/
function social_font_install() {
$font = Font::create([
'name' => 'Montserrat',
'user_id' => 1,
'created' => \Drupal::time()
->getRequestTime(),
'field_fallback' => '0',
]);
$font
->save();
// Set some default permissions.
_social_font_set_permissions();
}
/**
* Function to set permissions.
*/
function _social_font_set_permissions() {
$roles = Role::loadMultiple();
/** @var \Drupal\user\Entity\Role $role */
foreach ($roles as $role) {
if ($role
->id() === 'administrator') {
continue;
}
$permissions = _social_font_get_permissions($role
->id());
user_role_grant_permissions($role
->id(), $permissions);
}
}
/**
* Build the permissions for each role.
*
* @param string $role
* The role.
*
* @return array
* Returns an array containing permissions.
*/
function _social_font_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'], [
'add font entities',
'delete font entities',
'edit font entities',
'access font overview',
'view published font entities',
'view unpublished font entities',
]);
if (isset($permissions[$role])) {
return $permissions[$role];
}
return [];
}
Functions
Name | Description |
---|---|
social_font_install | The social_font install file. |
_social_font_get_permissions | Build the permissions for each role. |
_social_font_set_permissions | Function to set permissions. |