forked from oroinc/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigHandler.php
75 lines (63 loc) · 1.74 KB
/
ConfigHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
namespace Oro\Bundle\ConfigBundle\Form\Handler;
use Oro\Bundle\ConfigBundle\Config\ConfigManager;
use Oro\Bundle\FormBundle\Form\Handler\RequestHandlerTrait;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
class ConfigHandler
{
use RequestHandlerTrait;
/**
* @var ConfigManager
*/
protected $manager;
/**
* @param ConfigManager $manager
*/
public function __construct(ConfigManager $manager)
{
$this->manager = $manager;
}
/**
* @param ConfigManager $manager
*
* @return $this
*/
public function setConfigManager(ConfigManager $manager)
{
$this->manager = $manager;
return $this;
}
/**
* @return ConfigManager
*/
public function getConfigManager()
{
return $this->manager;
}
/**
* Process form
*
* @param FormInterface $form
*
* @param Request $request
* @return bool True on successful processing, false otherwise
*/
public function process(FormInterface $form, Request $request)
{
$settingsData = $this->manager->getSettingsByForm($form);
$form->setData($settingsData);
if (in_array($request->getMethod(), ['POST', 'PUT'])) {
$this->submitPostPutRequest($form, $request);
if ($form->isValid()) {
$changeSet = $this->manager->save($form->getData());
$handler = $form->getConfig()->getAttribute('handler');
if (null !== $handler && is_callable($handler)) {
call_user_func($handler, $this->manager, $changeSet, $form);
}
return true;
}
}
return false;
}
}