Commit 5cebff74 authored by Kyrylo Loboda's avatar Kyrylo Loboda
Browse files

Issue #3270190: Role is deleted when module is uninstalled

parent 052318ef
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -70,14 +70,24 @@ class TcaPermissionGenerator implements ContainerInjectionInterface {
        ->getEntityType();
      $permissions += [
        'tca administer ' . $def['entityType'] => [
          'title' => $this->t(
                      'Administer Token Content Access settings for %entity_type',
                      ['%entity_type' => $entity_type->getLabel()]),
          'title' => $this->t('Administer Token Content Access settings for %entity_type', [
            '%entity_type' => $entity_type->getLabel(),
          ]),
          'dependencies' => [
            'module' => [
              $def['provider'],
            ],
          ],
        ],
        'tca bypass ' . $def['entityType'] => [
          'title' => $this->t(
                      'Bypass Token Content Access action for %entity_type',
                      ['%entity_type' => $entity_type->getLabel()]),
          'title' => $this->t('Bypass Token Content Access action for %entity_type', [
            '%entity_type' => $entity_type->getLabel(),
          ]),
          'dependencies' => [
            'module' => [
              $def['provider'],
            ],
          ],
        ],
      ];
    }
+19 −0
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@
 * Contains tca.install.
 */

use Drupal\user\Entity\Role;

/**
 * Add the public field to TCA Settings entity.
 */
@@ -27,3 +29,20 @@ function tca_update_8101(&$sandbox) {
    }
  }
}

/**
 * Add TCA permission dependencies.
 */
function tca_update_8301(&$sandbox) {
  $plugin_manager = \Drupal::service('plugin.manager.tca_plugin');
  $roles = Role::loadMultiple();

  foreach ($plugin_manager->getDefinitions() as $def) {
    foreach ($roles as $role) {
      if ($role->hasPermission('tca administer ' . $def['entityType']) || $role->hasPermission('tca bypass ' . $def['entityType'])) {
        $role->calculateDependencies();
        $role->save();
      }
    }
  }
}