1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Braincrafted\Bundle\BootstrapBundle\Form\Extension; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Form\AbstractTypeExtension; |
6
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
7
|
|
|
use Symfony\Component\Form\FormView; |
8
|
|
|
use Symfony\Component\Form\FormInterface; |
9
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
10
|
|
|
|
11
|
|
|
use Braincrafted\Bundle\BootstrapBundle\Util\LegacyFormHelper; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* StaticControlExtension |
15
|
|
|
* |
16
|
|
|
* @package BraincraftedBootstrapBundle |
17
|
|
|
* @subpackage Form |
18
|
|
|
* @author André Püschel <[email protected]> |
19
|
|
|
* @copyright 2014 André Püschel |
20
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License |
21
|
|
|
* @link http://bootstrap.braincrafted.com Bootstrap for Symfony2 |
22
|
|
|
*/ |
23
|
|
|
class StaticControlExtension extends AbstractTypeExtension |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritDoc} |
27
|
|
|
*/ |
28
|
|
|
public function buildView(FormView $view, FormInterface $form, array $options) |
29
|
|
|
{ |
30
|
|
|
$view->vars['static_control'] = $form->getConfig()->getOption('static_control', false); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Add the static_control option |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
|
|
public function configureOptions(OptionsResolver $resolver) |
38
|
|
|
{ |
39
|
|
|
$resolver->setDefined(array('static_control')); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
46
|
|
|
{ |
47
|
|
|
/* We need to set it to disabled, so Symfony ignores the fact that there is no |
48
|
|
|
data submitted back for this field (mapping=>false is only two way, so not usable) */ |
49
|
|
|
if (isset($options['static_control']) && $options['static_control']) { |
50
|
|
|
$builder->setDisabled(true); |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* {@inheritdoc} |
56
|
|
|
* Although we only support a field that provides a somewhat text-value we extend the form field. |
57
|
|
|
* (to be more precise: all fields which will be rendered as form_widget_simple) |
58
|
|
|
* If not we would have to create for every of the text-based types an own extension class. |
59
|
|
|
* This way we also support new text-based types out of the box. |
60
|
|
|
*/ |
61
|
|
|
public function getExtendedType() |
62
|
|
|
{ |
63
|
|
|
// map old class to new one using LegacyFormHelper |
64
|
|
|
return LegacyFormHelper::getType('form'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|