RulesUiRouteSubscriber.php in Rules 8.3
File
src/Routing/RulesUiRouteSubscriber.php
View source
<?php
namespace Drupal\rules\Routing;
use Drupal\Core\Routing\RouteSubscriberBase;
use Drupal\Core\Routing\RoutingEvents;
use Drupal\rules\Ui\RulesUiDefinition;
use Drupal\rules\Ui\RulesUiManagerInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class RulesUiRouteSubscriber extends RouteSubscriberBase {
protected $rulesUiManager;
public function __construct(RulesUiManagerInterface $rules_ui_manager) {
$this->rulesUiManager = $rules_ui_manager;
}
protected function alterRoutes(RouteCollection $collection) {
foreach ($this->rulesUiManager
->getDefinitions() as $name => $definition) {
$ui_definition = $this->rulesUiManager
->getDefinition($name);
$this
->registerRoutes($ui_definition, $collection);
}
}
public static function getSubscribedEvents() {
$events = parent::getSubscribedEvents();
$events[RoutingEvents::ALTER] = [
'onAlterRoutes',
-210,
];
return $events;
}
protected function registerRoutes(RulesUiDefinition $ui_definition, RouteCollection $collection) {
$base_route = $collection
->get($ui_definition->base_route);
$options = [
'parameters' => $base_route
->getOption('parameters') ?: [],
'_admin_route' => $base_route
->getOption('_admin_route') ?: FALSE,
'_rules_ui' => $ui_definition->id,
];
$requirements = [
'_permission' => $ui_definition->permissions ?: $base_route
->getRequirement('_permission'),
];
$route = (new Route($base_route
->getPath() . '/add/{expression_id}'))
->addDefaults([
'_form' => '\\Drupal\\rules\\Form\\AddExpressionForm',
'_title_callback' => '\\Drupal\\rules\\Form\\AddExpressionForm::getTitle',
])
->addOptions($options)
->addRequirements($requirements);
$collection
->add($ui_definition->base_route . '.expression.add', $route);
$route = (new Route($base_route
->getPath() . '/edit/{uuid}'))
->addDefaults([
'_form' => '\\Drupal\\rules\\Form\\EditExpressionForm',
'_title_callback' => '\\Drupal\\rules\\Form\\EditExpressionForm::getTitle',
])
->addOptions($options)
->addRequirements($requirements);
$collection
->add($ui_definition->base_route . '.expression.edit', $route);
$route = (new Route($base_route
->getPath() . '/delete/{uuid}'))
->addDefaults([
'_form' => '\\Drupal\\rules\\Form\\DeleteExpressionForm',
'_title' => 'Delete expression',
])
->addOptions($options)
->addRequirements($requirements);
$collection
->add($ui_definition->base_route . '.expression.delete', $route);
$route = (new Route($base_route
->getPath() . '/break-lock'))
->addDefaults([
'_form' => '\\Drupal\\rules\\Form\\BreakLockForm',
'_title' => 'Break lock',
])
->addOptions($options)
->addRequirements($requirements);
$collection
->add($ui_definition->base_route . '.break_lock', $route);
$route = (new Route($base_route
->getPath() . '/autocomplete/{uuid}'))
->addDefaults([
'_controller' => '\\Drupal\\rules\\Controller\\AutocompleteController::autocomplete',
'uuid' => '',
])
->addOptions($options)
->addRequirements($requirements);
$collection
->add($ui_definition->base_route . '.autocomplete', $route);
}
}