You are here

menu_per_role.install in Menu Per Role 8

Same filename and directory in other branches
  1. 5 menu_per_role.install
  2. 6 menu_per_role.install
  3. 7 menu_per_role.install

File

menu_per_role.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the Menu Per Role module.
 */
declare (strict_types=1);
use Drupal\user\Entity\Role;

/**
 * Permission to bypass menu_per_role access to roles having old permission.
 */
function menu_per_role_update_8101() {
  $config = \Drupal::config('menu_per_role.settings');
  $admin_see_all = !is_null($config
    ->get('admin_see_all')) ? $config
    ->get('admin_see_all') : FALSE;
  if ($admin_see_all) {

    /** @var \Drupal\user\Entity\Role[] $roles */
    $roles = Role::loadMultiple();
    foreach ($roles as $role) {
      if ($role
        ->hasPermission('administer menu_per_role')) {
        $role
          ->grantPermission('bypass menu_per_role access');
        $role
          ->save();
      }
    }
  }
}

/**
 * Removes old config since it is replaced by permission.
 */
function menu_per_role_update_8102() {
  \Drupal::configFactory()
    ->getEditable('menu_per_role.settings')
    ->clear('uid1_see_all')
    ->clear('admin_see_all')
    ->save();
}

/**
 * Have distinct permissions for front and admin access bypass.
 */
function menu_per_role_update_8103() {

  /** @var \Drupal\user\Entity\Role[] $roles */
  $roles = Role::loadMultiple();
  foreach ($roles as $role) {
    if ($role
      ->hasPermission('bypass menu_per_role access')) {
      $role
        ->revokePermission('bypass menu_per_role access');
      $role
        ->grantPermission('bypass menu_per_role access front');
      $role
        ->grantPermission('bypass menu_per_role access admin');
      $role
        ->save();
    }
  }
}

/**
 * Init new settings for admin to bypass access.
 */
function menu_per_role_update_8104() {
  $config = \Drupal::configFactory()
    ->getEditable('menu_per_role.settings');
  $config
    ->set('admin_bypass_access_front', FALSE);
  $config
    ->set('admin_bypass_access_admin', TRUE);
  $config
    ->save();
}

Functions

Namesort descending Description
menu_per_role_update_8101 Permission to bypass menu_per_role access to roles having old permission.
menu_per_role_update_8102 Removes old config since it is replaced by permission.
menu_per_role_update_8103 Have distinct permissions for front and admin access bypass.
menu_per_role_update_8104 Init new settings for admin to bypass access.