You are here

function theme_switcher_user_role_delete in Theme Switcher Rules 8

Implements hook_ENTITY_TYPE_delete() for user_role entities.

Removes deleted role from blocks that use it.

File

./theme_switcher.module, line 61
Contains hook implementations for Theme Switcher module.

Code

function theme_switcher_user_role_delete($role) {
  foreach (ThemeSwitcherRule::loadMultiple() as $rule) {
    $visibility = $rule
      ->getVisibility();
    if (isset($visibility['user_role']['roles'][$role
      ->id()])) {
      unset($visibility['user_role']['roles'][$role
        ->id()]);
      $rule
        ->setVisibilityConfig('user_role', $visibility['user_role']);
      $rule
        ->save();
    }
  }
}