You are here

function block_visibility_groups_uninstall in Block Visibility Groups 8

Implements hook_uninstall().

File

./block_visibility_groups.install, line 11
Install, update and uninstall functions for the block_visibility_groups module.

Code

function block_visibility_groups_uninstall() {

  // Remove the 'condition_group' condition from all blocks.

  /** @var \Drupal\Core\Entity\EntityStorageInterface $block_storage */
  $block_storage = \Drupal::service('entity_type.manager')
    ->getStorage('block');

  /** @var \Drupal\block\Entity\Block[] $blocks */
  $blocks = $block_storage
    ->loadMultiple();
  foreach ($blocks as $block) {
    $conditions = $block
      ->getVisibilityConditions();
    if ($conditions
      ->has('condition_group')) {
      $conditions
        ->removeInstanceId('condition_group');
      $block
        ->save();
    }
  }
}