RouteSubscriber.php in Flexiform 8
File
contrib/wizard/src/Routing/RouteSubscriber.php
View source
<?php
namespace Drupal\flexiform_wizard\Routing;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
class RouteSubscriber extends RouteSubscriberBase {
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
public function alterRoutes(RouteCollection $collection) {
foreach ($this->entityTypeManager
->getStorage('flexiform_wizard')
->loadMultiple() as $wizard_id => $wizard) {
$options = [];
foreach ($wizard
->get('parameters') as $param_name => $param_info) {
$options['parameters'][$param_name] = [
'type' => 'entity:' . $param_info['entity_type'],
];
}
$options['parameters']['wizard'] = [
'type' => 'entity:flexiform_wizard',
];
$defaults = [
'_wizard' => '\\Drupal\\flexiform_wizard\\Wizard\\DefaultWizard',
'_title' => 'Wizard',
'wizard' => $wizard_id,
];
$route = new Route($wizard
->get('path'), $defaults, [
'_access' => 'TRUE',
], $options);
$collection
->add("flexiform_wizard.{$wizard_id}", $route);
$route = new Route($wizard
->get('path') . '/{step}', $defaults, [
'_access' => 'TRUE',
], $options);
$collection
->add("flexiform_wizard.{$wizard_id}.step", $route);
}
}
}