BlockVisibilityGroupController.php in Block Visibility Groups 8
File
src/Controller/BlockVisibilityGroupController.php
View source
<?php
namespace Drupal\block_visibility_groups\Controller;
use Drupal\block_visibility_groups\Entity\BlockVisibilityGroup;
use Drupal\Component\Serialization\Json;
use Drupal\Core\Condition\ConditionManager;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
class BlockVisibilityGroupController extends ControllerBase {
protected $conditionManager;
public function __construct(ConditionManager $plugin_manager_condition) {
$this->conditionManager = $plugin_manager_condition;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('plugin.manager.condition'));
}
public function index($param_1, $param_2) {
return [
'#type' => 'markup',
'#markup' => $this
->t('Implement method: index with parameter(s): $param_1, $param_2'),
];
}
public function selectCondition(BlockVisibilityGroup $block_visibility_group, $redirect) {
$build = [
'#theme' => 'links',
'#links' => [],
];
$available_plugins = $this->conditionManager
->getDefinitions();
unset($available_plugins['condition_group']);
foreach ($available_plugins as $condition_id => $condition) {
$build['#links'][$condition_id] = [
'title' => $condition['label'],
'url' => Url::fromRoute('block_visibility_groups.condition_add', [
'block_visibility_group' => $block_visibility_group
->id(),
'condition_id' => $condition_id,
'redirect' => $redirect,
]),
'attributes' => [
'class' => [
'use-ajax',
],
'data-dialog-type' => 'modal',
'data-dialog-options' => Json::encode([
'width' => 'auto',
]),
],
];
}
return $build;
}
}