function block_user_role_delete

block_user_role_delete($role)

Implements hook_ENTITY_TYPE_delete() for user_role entities.

Removes deleted role from blocks that use it.

File

core/modules/block/block.module, line 245
Controls the visual building blocks a page is constructed with.

Code

function block_user_role_delete($role) {
  foreach (Block::loadMultiple() as $block) {
    /** @var $block \Drupal\block\BlockInterface */
    $visibility = $block->getVisibility();
    if (isset($visibility['user_role']['roles'][$role->id()])) {
      unset($visibility['user_role']['roles'][$role->id()]);
      $block->setVisibilityConfig('user_role', $visibility['user_role']);
      $block->save();
    }
  }
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!block!block.module/function/block_user_role_delete/8.1.x