Version 1
[yaffs-website] / web / modules / contrib / ctools / src / Controller / WizardEntityFormController.php
1 <?php
2
3 namespace Drupal\ctools\Controller;
4
5 use Drupal\Core\Controller\ControllerResolverInterface;
6 use Drupal\Core\Entity\EntityManagerInterface;
7 use Drupal\Core\Form\FormBuilderInterface;
8 use Drupal\Core\Routing\RouteMatchInterface;
9 use Drupal\ctools\Wizard\WizardFactoryInterface;
10
11 /**
12  * Wrapping controller for wizard forms that serve as the main page body.
13  */
14 class WizardEntityFormController extends WizardFormController {
15
16   /**
17    * The entity manager service.
18    *
19    * @var \Drupal\Core\Entity\EntityManagerInterface
20    */
21   protected $entityManager;
22
23   /**
24    * @param \Drupal\Core\Controller\ControllerResolverInterface $controller_resolver
25    *   The controller resolver.
26    * @param \Drupal\Core\Form\FormBuilderInterface $form_builder
27    *   The form builder.
28    * @param \Drupal\ctools\Wizard\WizardFactoryInterface $wizard_factory
29    *   The wizard factory.
30    * @param \Drupal\Core\Entity\EntityManagerInterface $manager
31    *   The entity manager.
32    */
33   public function __construct(ControllerResolverInterface $controller_resolver, FormBuilderInterface $form_builder, WizardFactoryInterface $wizard_factory, EntityManagerInterface $manager) {
34     parent::__construct($controller_resolver, $form_builder, $wizard_factory);
35     $this->entityManager = $manager;
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   protected function getFormArgument(RouteMatchInterface $route_match) {
42     $form_arg = $route_match->getRouteObject()->getDefault('_entity_wizard');
43     list($entity_type_id, $operation) = explode('.', $form_arg);
44     $definition = $this->entityManager->getDefinition($entity_type_id);
45     $handlers = $definition->getHandlerClasses();
46     if (empty($handlers['wizard'][$operation])) {
47       throw new \Exception(sprintf('Unsupported wizard operation %s', $operation));
48     }
49     return $handlers['wizard'][$operation];
50   }
51
52 }