-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathFormFlowHiddenFieldExtension.php
More file actions
66 lines (56 loc) · 1.73 KB
/
Copy pathFormFlowHiddenFieldExtension.php
File metadata and controls
66 lines (56 loc) · 1.73 KB
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
<?php
namespace Craue\FormFlowBundle\Form\Extension;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
/**
* @author Konstantin Myakshin <koc-dp@yandex.ru>
* @author Christian Raue <christian.raue@gmail.com>
* @copyright 2011-2015 Christian Raue
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
class FormFlowHiddenFieldExtension extends AbstractTypeExtension {
/**
* {@inheritDoc}
*/
public function getExtendedType() {
return 'hidden';
}
/**
* {@inheritDoc}
*/
public function configureOptions(OptionsResolver $resolver) {
$optionNames = array(
'flow_instance_key',
'flow_step_key',
);
if (Kernel::VERSION_ID < 20600) {
$resolver->setOptional($optionNames);
} else {
$resolver->setDefined($optionNames);
}
}
/**
* {@inheritDoc}
*/
// TODO remove as soon as Symfony >= 2.7 is required
public function setDefaultOptions(OptionsResolverInterface $resolver) {
$this->configureOptions($resolver);
}
/**
* {@inheritDoc}
*/
public function finishView(FormView $view, FormInterface $form, array $options) {
if (array_key_exists('flow_instance_key', $options) && $view->vars['name'] === $options['flow_instance_key']) {
$view->vars['value'] = $options['data'];
$view->vars['full_name'] = $options['flow_instance_key'];
}
if (array_key_exists('flow_step_key', $options) && $view->vars['name'] === $options['flow_step_key']) {
$view->vars['value'] = $options['data'];
$view->vars['full_name'] = $options['flow_step_key'];
}
}
}