You are here

social_language.install in Open Social 8

Install, update and uninstall functions for the social_language module.

File

modules/custom/social_language/social_language.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the social_language module.
 */
use Drupal\user\Entity\Role;

/**
 * Implements hook_install().
 *
 * Perform actions related to the installation of social_language.
 */
function social_language_install() {

  // Set some default permissions.
  _social_language_set_permissions();
  \Drupal::configFactory()
    ->getEditable('locale.settings')
    ->set('translation.path', '/tmp')
    ->save();
}

/**
 * Function to set permissions.
 */
function _social_language_set_permissions() {
  $roles = Role::loadMultiple();

  /** @var \Drupal\user\Entity\Role $role */
  foreach ($roles as $role) {
    if ($role
      ->id() === 'administrator') {
      continue;
    }
    $permissions = _social_language_get_permissions($role
      ->id());
    user_role_grant_permissions($role
      ->id(), $permissions);
  }
}

/**
 * Build the permissions.
 */
function _social_language_get_permissions($role) {

  // Site manager.
  $permissions['sitemanager'] = [
    'create content translations',
    'delete content translations',
    'update content translations',
    'translate menu_link_content',
    'translate account settings',
    'translate system information',
  ];
  if (isset($permissions[$role])) {
    return $permissions[$role];
  }
  return [];
}

Functions

Namesort descending Description
social_language_install Implements hook_install().
_social_language_get_permissions Build the permissions.
_social_language_set_permissions Function to set permissions.