You are here

function taxonomy_access_fix_update_8202 in Taxonomy access fix 8.2

Migrate from 'Add terms in %vocabulary' permission to Drupal Core permission.

File

./taxonomy_access_fix.install, line 28
Install, uninstall and update hooks for taxonomy_access_fix module.

Code

function taxonomy_access_fix_update_8202() {
  $vocabularies = Vocabulary::loadMultiple();
  foreach (Role::loadMultiple() as $role) {
    foreach ($vocabularies as $vocabulary) {
      $role
        ->grantPermission('view terms in ' . $vocabulary
        ->id())
        ->save();
      if ($role
        ->hasPermission('add terms in ' . $vocabulary
        ->id())) {
        $role
          ->grantPermission('create terms in ' . $vocabulary
          ->id());

        // Revoke the old permission so that it would be hidden, if it was
        // deprecated (@see Issue 2924785).
        $role
          ->revokePermission('add terms in ' . $vocabulary
          ->id());
        $role
          ->save();
      }
    }
  }
  return t('The "@old_permission_label" permissions provided by @module_name have been migrated to the new "@new_permission_label" permissions provided by Drupal Core. You may want to <a href=":permissions_url">review the updated permissions</a>.', [
    '@old_permission_label' => t('Add terms in %vocabulary', [
      '%vocabulary' => t('Vocabulary label'),
    ]),
    '@new_permission_label' => t('%vocabulary: Create terms', [
      '%vocabulary' => t('Vocabulary label'),
    ]),
    '@module_name' => t('Taxonomy Access Fix'),
    ':permissions_url' => Url::fromRoute('user.admin_permissions')
      ->toString(),
  ]);
}