You are here

function thunder_update_8108 in Thunder 8.2

Adjust access permissions related to "access_unpublished" module.

File

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

Code

function thunder_update_8108() {

  /** @var \Drupal\update_helper\UpdateLogger $updateLogger */
  $updateLogger = \Drupal::service('update_helper.logger');

  // Granting permissions only for "anonymous" and "authenticated" user roles.
  $roles = Role::loadMultiple([
    'anonymous',
    'authenticated',
  ]);
  foreach ($roles as $role) {
    if ($role
      ->hasPermission('access content')) {
      try {
        $role
          ->grantPermission('access_unpublished node article');
        $role
          ->save();
        $updateLogger
          ->info(t('Permission for accessing unpublished node with generated token Url is granted for @user_role user role.', [
          '@user_role' => $role
            ->id(),
        ]));
      } catch (EntityStorageException $storageException) {
        $updateLogger
          ->warning(t('Unable to change permissions for @user_role user role.', [
          '@user_role' => $role
            ->id(),
        ]));
      }
    }
    else {
      $updateLogger
        ->info(t('Skipping @user_role user role, because of non-sufficient permissions.', [
        '@user_role' => $role
          ->id(),
      ]));
    }
  }

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