GroupInfo.php in Block Visibility Groups 8
File
block_visibility_groups_admin/src/GroupInfo.php
View source
<?php
namespace Drupal\block_visibility_groups_admin;
use Drupal\block_visibility_groups\GroupEvaluator;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Executable\ExecutableManagerInterface;
class GroupInfo implements GroupInfoInterface {
protected $block_visibility_groups_group_evaluator;
protected $group_storage;
protected $condition_manager;
public function __construct(GroupEvaluator $block_visibility_groups_group_evaluator, EntityTypeManagerInterface $entity_manager, ExecutableManagerInterface $condition_manager) {
$this->block_visibility_groups_group_evaluator = $block_visibility_groups_group_evaluator;
$this->group_storage = $entity_manager
->getStorage('block_visibility_group');
$this->condition_manager = $condition_manager;
}
public function getActiveGroups() {
$active_groups = [];
foreach ($this->group_storage
->loadMultiple() as $id => $group) {
$condition = $this->condition_manager
->createInstance('condition_group', [
'block_visibility_group' => $id,
]);
if ($condition
->evaluate()) {
$active_groups[$id] = $group;
}
}
return $active_groups;
}
}