class RulesUiRouteSubscriber in Rules 8.3
Adds routes generated by the rules UI handlers.
Hierarchy
- class \Drupal\Core\Routing\RouteSubscriberBase implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
- class \Drupal\rules\Routing\RulesUiRouteSubscriber
 
 
Expanded class hierarchy of RulesUiRouteSubscriber
1 string reference to 'RulesUiRouteSubscriber'
1 service uses RulesUiRouteSubscriber
File
- src/
Routing/ RulesUiRouteSubscriber.php, line 15  
Namespace
Drupal\rules\RoutingView source
class RulesUiRouteSubscriber extends RouteSubscriberBase {
  /**
   * The rules UI manager.
   *
   * @var \Drupal\rules\Ui\RulesUiManagerInterface
   */
  protected $rulesUiManager;
  /**
   * Constructs the object.
   *
   * @param \Drupal\rules\Ui\RulesUiManagerInterface $rules_ui_manager
   *   The rules UI manager.
   */
  public function __construct(RulesUiManagerInterface $rules_ui_manager) {
    $this->rulesUiManager = $rules_ui_manager;
  }
  /**
   * {@inheritdoc}
   */
  protected function alterRoutes(RouteCollection $collection) {
    foreach ($this->rulesUiManager
      ->getDefinitions() as $name => $definition) {
      $ui_definition = $this->rulesUiManager
        ->getDefinition($name);
      $this
        ->registerRoutes($ui_definition, $collection);
    }
  }
  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events = parent::getSubscribedEvents();
    // Should run after AdminRouteSubscriber so the routes can inherit admin
    // status of the edit routes on entities. Therefore priority -210.
    $events[RoutingEvents::ALTER] = [
      'onAlterRoutes',
      -210,
    ];
    return $events;
  }
  /**
   * Registers the routes as needed for the UI.
   *
   * @param \Drupal\rules\Ui\RulesUiDefinition $ui_definition
   *   The definition of the RulesUI for which to register the routes.
   * @param \Symfony\Component\Routing\RouteCollection $collection
   *   The route collection to which to add the routes.
   */
  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 for editing expressions in a Rule.
    $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 for deleting expressions from a Rule.
    $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 to break the lock of an edited rule.
    $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 for data selector autocomplete.
    $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);
  }
}Members
| 
            Name | 
                  Modifiers | Type | Description | Overrides | 
|---|---|---|---|---|
| 
            RouteSubscriberBase:: | 
                  public | function | Delegates the route altering to self::alterRoutes(). | 1 | 
| 
            RulesUiRouteSubscriber:: | 
                  protected | property | The rules UI manager. | |
| 
            RulesUiRouteSubscriber:: | 
                  protected | function | 
            Alters existing routes for a specific collection. Overrides RouteSubscriberBase:: | 
                  |
| 
            RulesUiRouteSubscriber:: | 
                  public static | function | 
            Returns an array of event names this subscriber wants to listen to. Overrides RouteSubscriberBase:: | 
                  |
| 
            RulesUiRouteSubscriber:: | 
                  protected | function | Registers the routes as needed for the UI. | |
| 
            RulesUiRouteSubscriber:: | 
                  public | function | Constructs the object. |