GroupLister.php in Block Visibility Groups 8
File
block_visibility_groups_admin/src/Controller/GroupLister.php
View source
<?php
namespace Drupal\block_visibility_groups_admin\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
class GroupLister extends ControllerBase {
protected $group_info;
protected $storage;
public function __construct(EntityTypeManager $entityTypeManager) {
$this->storage = $entityTypeManager
->getStorage('block_visibility_group');
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'));
}
public function activeList($active_group_ids) {
$active_group_ids = explode(',', $active_group_ids);
$groups = $this->storage
->loadMultiple($active_group_ids);
$edit_links = [];
foreach ($groups as $group) {
$edit_links[] = [
'#type' => 'container',
'edit' => [
'#type' => 'link',
'#title' => $group
->label(),
'#url' => $group
->toUrl('edit-form'),
'#suffix' => ' - ',
],
'manage' => [
'#type' => 'link',
'#title' => $this
->t('Manage Blocks'),
'#url' => Url::fromRoute('block.admin_display_theme', [
'theme' => \Drupal::theme()
->getActiveTheme()
->getName(),
], [
'query' => [
'block_visibility_group' => $group
->id(),
],
]),
],
];
}
return $edit_links;
}
}