1 | <?php |
||
31 | class InjectFormMiddleware extends OnBeginMiddleware implements SendsMiddlewareSignal |
||
32 | { |
||
33 | /** |
||
34 | * @see InjectFormMiddleware |
||
35 | */ |
||
36 | protected function process() |
||
37 | { |
||
38 | $this->beforeSignal()->dispatch(); |
||
39 | |||
40 | $formClassName = $this->getFormObject()->getClassName(); |
||
41 | $formName = $this->getFormObject()->getName(); |
||
42 | |||
43 | if (false === $this->getRequest()->hasArgument($formName)) { |
||
44 | /* |
||
45 | * Creating an empty instance of the form. |
||
46 | */ |
||
47 | $form = Core::get()->getObjectManager()->getEmptyObject($formClassName); |
||
48 | |||
49 | /* |
||
50 | * The request argument with the name of the form is filled with the |
||
51 | * new form instance. |
||
52 | */ |
||
53 | $this->getRequest()->setArgument($formName, $form); |
||
54 | |||
55 | /* |
||
56 | * The form instance is injected in the form object, for further |
||
57 | * usage. |
||
58 | */ |
||
59 | $this->getFormObject()->setForm($form); |
||
60 | |||
61 | /* |
||
62 | * The after-signal should be dispatched only if the form was |
||
63 | * actually injected in the request, otherwise the other middlewares |
||
64 | * should not be called. |
||
65 | */ |
||
66 | $this->afterSignal()->dispatch(); |
||
67 | } |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @return int |
||
72 | */ |
||
73 | public function getPriority() |
||
77 | |||
78 | /** |
||
79 | * @return array |
||
80 | */ |
||
81 | public function getAllowedSignals() |
||
85 | } |
||
86 |