function block_user_role_delete

Same name in other branches
  1. 7.x modules/block/block.module \block_user_role_delete()
  2. 9 core/modules/block/block.module \block_user_role_delete()
  3. 10 core/modules/block/block.module \block_user_role_delete()

Implements hook_ENTITY_TYPE_delete() for user_role entities.

Removes deleted role from blocks that use it.

File

core/modules/block/block.module, line 246

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();
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.