You are here

function thunder_update_8124 in Thunder 8.2

Adjust access permissions related to "access_unpublish" module.

File

./thunder.install, line 938
Install, update and uninstall functions for the thunder installation profile.

Code

function thunder_update_8124() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updateLogger = $updater
    ->logger();

  // Granting permissions only for "editor" and "seo" user roles.
  $roles = Role::loadMultiple([
    'editor',
    'seo',
  ]);
  $successful = TRUE;
  foreach ($roles as $role) {
    try {
      $role
        ->grantPermission('delete token');
      $role
        ->grantPermission('renew token');
      $role
        ->save();
      $updateLogger
        ->info(t('Permissions for deleting and renewing access tokens is granted for @user_role user role.', [
        '@user_role' => $role
          ->id(),
      ]));
    } catch (EntityStorageException $storageException) {
      $successful = FALSE;
      $updateLogger
        ->warning(t('Unable to change permissions for @user_role user role.', [
        '@user_role' => $role
          ->id(),
      ]));
    }
  }
  _thunder_mark_update_checklist('thunder__thunder_update_8124', $successful, $updateLogger);

  // Output logged result of update hook execution.
  return $updateLogger
    ->output();
}