RouteConditionCreator.php in Block Visibility Groups 8
File
block_visibility_groups_admin/src/Plugin/ConditionCreator/RouteConditionCreator.php
View source
<?php
namespace Drupal\block_visibility_groups_admin\Plugin\ConditionCreator;
use Drupal\block_visibility_groups_admin\Plugin\ConditionCreatorBase;
class RouteConditionCreator extends ConditionCreatorBase {
public function getNewConditionLabel() {
$current_path = $this
->getPathPattern();
return $this
->t('Current path: @path', [
'@path' => $current_path,
]);
}
protected function getPathPattern() {
$route = $this->route
->getRouteObject();
$path = $route
->getPath();
$parameters = $route
->compile()
->getPathVariables();
foreach ($parameters as $parameter) {
$path = str_replace('{' . $parameter . '}', '*', $path);
}
return $path;
}
public function createConditionElements() {
$elements = parent::createConditionElements();
$elements['condition_config'] = [
'#type' => 'value',
'#value' => [
'pages' => $this
->getPathPattern(),
],
];
return $elements;
}
}