1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* 2017 Romain CANON <[email protected]> |
4
|
|
|
* |
5
|
|
|
* This file is part of the TYPO3 FormZ project. |
6
|
|
|
* It is free software; you can redistribute it and/or modify it |
7
|
|
|
* under the terms of the GNU General Public License, either |
8
|
|
|
* version 3 of the License, or any later version. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, see: |
11
|
|
|
* http://www.gnu.org/licenses/gpl-3.0.html |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Romm\Formz\Middleware\Item\Persistence; |
15
|
|
|
|
16
|
|
|
use Romm\Formz\Middleware\Item\DefaultMiddleware; |
17
|
|
|
use Romm\Formz\Middleware\State\PresetMiddlewareInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* This middleware will check if the form was submitted, and inject it in every |
21
|
|
|
* persistence service bound to the form object. |
22
|
|
|
* |
23
|
|
|
* Note that you can deactivate the form injection in your own middlewares: |
24
|
|
|
* @see \Romm\Formz\Middleware\Item\Persistence\PersistenceMiddlewareService::setInjectionFlag() |
25
|
|
|
*/ |
26
|
|
|
class PersistenceInjectionMiddleware extends DefaultMiddleware implements PresetMiddlewareInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var PersistenceMiddlewareService |
30
|
|
|
*/ |
31
|
|
|
protected $service; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @see PersistenceInjectionMiddleware |
35
|
|
|
*/ |
36
|
|
|
public function process() |
37
|
|
|
{ |
38
|
|
|
if ($this->service->hasIdentifierObject() |
39
|
|
|
&& true === $this->service->getInjectionFlag() |
40
|
|
|
&& $this->getFormObject()->formWasSubmitted() |
41
|
|
|
) { |
42
|
|
|
$this->getFormObject() |
43
|
|
|
->getPersistenceManager() |
44
|
|
|
->save($this->service->getIdentifierObject(), $this->getFormObject()->getForm()); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param PersistenceMiddlewareService $service |
50
|
|
|
*/ |
51
|
|
|
public function injectService(PersistenceMiddlewareService $service) |
52
|
|
|
{ |
53
|
|
|
$this->service = $service; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|