1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* UpdateViewer.php |
4
|
|
|
* |
5
|
|
|
* @since 29/05/15 |
6
|
|
|
* @author gseidel |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Enhavo\Bundle\AppBundle\Viewer\Viewer; |
10
|
|
|
|
11
|
|
|
use Enhavo\Bundle\AppBundle\Controller\RequestConfiguration; |
12
|
|
|
use Sylius\Component\Resource\Metadata\MetadataInterface; |
13
|
|
|
use Sylius\Component\Resource\Model\ResourceInterface; |
14
|
|
|
use Symfony\Component\HttpFoundation\ParameterBag; |
15
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
16
|
|
|
|
17
|
|
|
class UpdateViewer extends CreateViewer |
18
|
|
|
{ |
19
|
|
|
public function getType() |
20
|
|
|
{ |
21
|
|
|
return 'update'; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
protected function buildTemplateParameters(ParameterBag $parameters, RequestConfiguration $requestConfiguration, array $options) |
25
|
|
|
{ |
26
|
|
|
parent::buildTemplateParameters($parameters, $requestConfiguration, $options); |
27
|
|
|
|
28
|
|
|
/** @var MetadataInterface $metadata */ |
29
|
|
|
$metadata = $options['metadata']; |
30
|
|
|
/** @var ResourceInterface $resource */ |
31
|
|
|
$resource = $options['resource']; |
32
|
|
|
|
33
|
|
|
$parameters->set('form_action', $this->mergeConfig([ |
34
|
|
|
sprintf('%s_%s_update', $metadata->getApplicationName(), $this->getUnderscoreName($metadata)), |
35
|
|
|
$options['form_action'], |
36
|
|
|
$this->getViewerOption('form.action', $requestConfiguration) |
37
|
|
|
])); |
38
|
|
|
|
39
|
|
|
$parameters->set('form_action_parameters', $this->mergeConfigArray([ |
40
|
|
|
[ 'id' => $resource->getId() ], |
41
|
|
|
$options['form_action_parameters'], |
42
|
|
|
$this->getViewerOption('form.action_parameters', $requestConfiguration) |
43
|
|
|
])); |
44
|
|
|
|
45
|
|
|
$actionsSecondary = $this->mergeConfigArray([ |
46
|
|
|
$this->createActionsSecondary($options, $requestConfiguration, $resource), |
47
|
|
|
$options['actions_secondary'], |
48
|
|
|
$this->getViewerOption('actions_secondary', $requestConfiguration) |
49
|
|
|
]); |
50
|
|
|
|
51
|
|
|
$data = $parameters->get('data'); |
52
|
|
|
$data['actionsSecondary'] = $this->actionManager->createActionsViewData($actionsSecondary, $options['resource']); |
53
|
|
|
|
54
|
|
|
$resourceData = $this->getResourceData($requestConfiguration, $options); |
55
|
|
|
if ($resourceData) { |
56
|
|
|
$data['resource'] = $resourceData; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$parameters->set('data', $data); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
private function createActionsSecondary($options, $requestConfiguration, $resource) |
|
|
|
|
63
|
|
|
{ |
64
|
|
|
/** @var MetadataInterface $metadata */ |
65
|
|
|
$metadata = $options['metadata']; |
66
|
|
|
|
67
|
|
|
$formDelete = $this->mergeConfig([ |
68
|
|
|
sprintf('%s_%s_delete', $metadata->getApplicationName(), $this->getUnderscoreName($metadata)), |
69
|
|
|
$options['form_delete'], |
70
|
|
|
$this->getViewerOption('form.delete', $requestConfiguration) |
71
|
|
|
]); |
72
|
|
|
|
73
|
|
|
$formDeleteParameters = $this->mergeConfigArray([ |
74
|
|
|
$options['form_delete_parameters'], |
75
|
|
|
$this->getViewerOption('form.delete_parameters', $requestConfiguration) |
76
|
|
|
]); |
77
|
|
|
|
78
|
|
|
$default = [ |
79
|
|
|
'delete' => [ |
80
|
|
|
'type' => 'delete', |
81
|
|
|
'route' => $formDelete, |
82
|
|
|
'route_parameters' => $formDeleteParameters, |
83
|
|
|
'permission' => $this->getRoleNameByResourceName($metadata->getApplicationName(), $this->getUnderscoreName($metadata), 'delete') |
84
|
|
|
] |
85
|
|
|
]; |
86
|
|
|
|
87
|
|
|
return $default; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
View Code Duplication |
private function getResourceData(RequestConfiguration $requestConfiguration, array $options) |
|
|
|
|
91
|
|
|
{ |
92
|
|
|
$resourceData = null; |
93
|
|
|
$serializationGroups = $requestConfiguration->getSerializationGroups(); |
94
|
|
|
if($serializationGroups && $options['resource']) { |
95
|
|
|
$resourceData = $this->container->get('serializer')->normalize($options['resource'], null, ['groups' => $serializationGroups]); |
96
|
|
|
} |
97
|
|
|
return $resourceData; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
public function configureOptions(OptionsResolver $optionsResolver) |
102
|
|
|
{ |
103
|
|
|
parent::configureOptions($optionsResolver); |
104
|
|
|
$optionsResolver->setDefaults([ |
105
|
|
|
'form_delete' => null, |
106
|
|
|
'form_delete_parameters' => [], |
107
|
|
|
'label' => 'label.edit' |
108
|
|
|
]); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.