You are here

protected function BlockVisibilityGroupedListBuilder::getEntityIds in Block Visibility Groups 8

Unset blocks that should not be shown with current group.

Overrides BlockListBuilder::getEntityIds

File

src/BlockVisibilityGroupedListBuilder.php, line 296

Class

BlockVisibilityGroupedListBuilder
Extends BlockListBuilder to add our elements only show certain blocks.

Namespace

Drupal\block_visibility_groups

Code

protected function getEntityIds() {
  $entity_ids = parent::getEntityIds();
  $current_block_visibility_group = $this
    ->getCurrentBlockVisibilityGroup();
  $show_global_in_group = $this
    ->getShowGlobalWithGroup();
  if (!empty($current_block_visibility_group) && $current_block_visibility_group != $this::ALL_GROUP) {
    $entities = $this->storage
      ->loadMultipleOverrideFree($entity_ids);

    /** @var Block $block */
    foreach ($entities as $block) {
      $config_block_visibility_group = $this
        ->getGroupForBlock($block);
      if (static::UNSET_GROUP == $current_block_visibility_group) {
        if (!empty($config_block_visibility_group)) {
          unset($entity_ids[$block
            ->id()]);
        }
      }
      elseif ($config_block_visibility_group != $current_block_visibility_group && !(empty($config_block_visibility_group) && $show_global_in_group)) {
        unset($entity_ids[$block
          ->id()]);
      }
    }
  }
  return $entity_ids;
}