3 namespace Drupal\ctools\Controller;
5 use Drupal\Core\Controller\ControllerResolverInterface;
6 use Drupal\Core\Controller\FormController;
7 use Drupal\Core\Form\FormBuilderInterface;
8 use Drupal\Core\Routing\RouteMatchInterface;
9 use Drupal\ctools\Wizard\FormWizardInterface;
10 use Drupal\ctools\Wizard\WizardFactoryInterface;
11 use Symfony\Component\HttpFoundation\Request;
14 * Wrapping controller for wizard forms that serve as the main page body.
16 class WizardFormController extends FormController {
21 * @var \Drupal\Core\DependencyInjection\ClassResolverInterface;
23 protected $classResolver;
26 * Tempstore Factory for keeping track of values in each step of the wizard.
28 * @var \Drupal\user\SharedTempStoreFactory
33 * The event dispatcher.
35 * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
37 protected $dispatcher;
40 * @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver
41 * The controller resolver.
42 * @param \Drupal\Core\Form\FormBuilderInterface $form_builder
44 * @param \Drupal\ctools\Wizard\WizardFactoryInterface $wizard_factory
47 public function __construct(ControllerResolverInterface $controller_resolver, FormBuilderInterface $form_builder, WizardFactoryInterface $wizard_factory) {
48 parent::__construct($controller_resolver, $form_builder);
49 $this->wizardFactory = $wizard_factory;
55 protected function getFormArgument(RouteMatchInterface $route_match) {
56 return $route_match->getRouteObject()->getDefault('_wizard');
60 * Wizards are not instantiated as simply as forms, so this method is unused.
62 protected function getFormObject(RouteMatchInterface $route_match, $form_arg) {
63 if (!is_subclass_of($form_arg, '\Drupal\ctools\Wizard\FormWizardInterface')) {
64 throw new \Exception("The _wizard default must reference a class instance of \\Drupal\\ctools\\Wizard\\FormWizardInterface.");
66 $parameters = $route_match->getParameters()->all();
67 $parameters += $form_arg::getParameters();
68 $parameters['route_match'] = $route_match;
69 return $this->wizardFactory->createWizard($form_arg, $parameters);
75 public function getContentResult(Request $request, RouteMatchInterface $route_match) {
76 $wizard = $this->getFormObject($route_match, $this->getFormArgument($route_match));
77 $ajax = $request->attributes->get('js') == 'ajax' ? TRUE : FALSE;
79 return $this->wizardFactory->getWizardForm($wizard, $request->attributes->all(), $ajax);