1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Component\Grid\Definition; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
class ArrayToDefinitionConverter implements ArrayToDefinitionConverterInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* {@inheritdoc} |
21
|
|
|
*/ |
22
|
|
|
public function convert($code, array $configuration) |
23
|
|
|
{ |
24
|
|
|
$grid = Grid::fromCodeAndDriverConfiguration($code, $configuration['driver']['name'], $configuration['driver']['options']); |
25
|
|
|
|
26
|
|
|
if (array_key_exists('sorting', $configuration)) { |
27
|
|
|
$grid->setSorting($configuration['sorting']); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
foreach ($configuration['fields'] as $name => $fieldConfiguration) { |
31
|
|
|
$field = Field::fromNameAndType($name, $fieldConfiguration['type']); |
32
|
|
|
|
33
|
|
|
if (array_key_exists('path', $fieldConfiguration)) { |
34
|
|
|
$field->setPath($fieldConfiguration['path']); |
35
|
|
|
} |
36
|
|
|
if (array_key_exists('label', $fieldConfiguration)) { |
37
|
|
|
$field->setLabel($fieldConfiguration['label']); |
38
|
|
|
} |
39
|
|
|
if (array_key_exists('options', $fieldConfiguration)) { |
40
|
|
|
$field->setOptions($fieldConfiguration['options']); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$grid->addField($field); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
foreach ($configuration['filters'] as $name => $filterConfiguration) { |
47
|
|
|
$filter = Filter::fromNameAndType($name, $filterConfiguration['type']); |
48
|
|
|
|
49
|
|
|
if (array_key_exists('label', $filterConfiguration)) { |
50
|
|
|
$filter->setLabel($filterConfiguration['label']); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$grid->addFilter($filter); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
foreach ($configuration['actions'] as $groupName => $actions) { |
57
|
|
|
$actionGroup = ActionGroup::named($groupName); |
58
|
|
|
|
59
|
|
|
foreach ($actions as $name => $actionConfiguration) { |
60
|
|
|
$action = Action::fromNameAndType($name, $actionConfiguration['type']); |
61
|
|
|
|
62
|
|
|
if (array_key_exists('label', $actionConfiguration)) { |
63
|
|
|
$action->setLabel($actionConfiguration['label']); |
64
|
|
|
} |
65
|
|
|
if (array_key_exists('options', $actionConfiguration)) { |
66
|
|
|
$action->setOptions($actionConfiguration['options']); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
$actionGroup->addAction($action); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$grid->addActionGroup($actionGroup); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return $grid; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|