1 | <?php |
||
15 | class ButtonTypeExtension extends AbstractTypeExtension |
||
16 | { |
||
17 | public function buildView(FormView $view, FormInterface $form, array $options) |
||
18 | { |
||
19 | /** @var FormInterface | ClickableInterface $form */ |
||
20 | if (!$form instanceof ClickableInterface) { |
||
21 | return; |
||
22 | } |
||
23 | |||
24 | $viewRoot = FormHelper::getViewRoot($view); |
||
25 | if (!$this->hasRuleBuilderContext($viewRoot)) { |
||
26 | return; |
||
27 | } |
||
28 | |||
29 | /** @var FormRuleContextBuilder $context */ |
||
30 | $context = $viewRoot->vars['rule_builder']; |
||
31 | $context->addButton($view, FormHelper::getValidationGroups($form)); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * {@inheritdoc} |
||
36 | */ |
||
37 | public function getExtendedType() |
||
38 | { |
||
39 | return FormHelper::isSymfony3Compatible() ? ButtonType::class : 'button'; |
||
40 | } |
||
41 | |||
42 | protected function hasRuleBuilderContext(FormView $view) |
||
46 | } |
||
47 |