GenericFormElement   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
c 2
b 0
f 0
dl 0
loc 51
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A configureOptions() 0 9 1
A createForm() 0 3 1
A getSuccessRouteParameters() 0 3 1
A getRoute() 0 3 1
A setFormFactory() 0 3 1
A getSuccessRoute() 0 3 1
1
<?php
2
3
/**
4
 * (c) FSi sp. z o.o. <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace FSi\Bundle\AdminBundle\Admin\CRUD;
13
14
use FSi\Bundle\AdminBundle\Admin\AbstractElement;
15
use FSi\Bundle\AdminBundle\Exception\RuntimeException;
16
use Symfony\Component\Form\FormFactoryInterface;
17
use Symfony\Component\Form\FormInterface;
18
use Symfony\Component\OptionsResolver\OptionsResolver;
19
20
abstract class GenericFormElement extends AbstractElement implements FormElement
21
{
22
    /**
23
     * @var FormFactoryInterface
24
     */
25
    protected $formFactory;
26
27
    public function getRoute(): string
28
    {
29
        return 'fsi_admin_form';
30
    }
31
32
    public function configureOptions(OptionsResolver $resolver): void
33
    {
34
        $resolver->setDefaults([
35
            'template_form' => null,
36
            'allow_add' => true
37
        ]);
38
39
        $resolver->setAllowedTypes('template_form', ['null', 'string']);
40
        $resolver->setAllowedTypes('allow_add', 'bool');
41
    }
42
43
    public function setFormFactory(FormFactoryInterface $factory): void
44
    {
45
        $this->formFactory = $factory;
46
    }
47
48
    public function createForm($data = null): FormInterface
49
    {
50
        return $this->initForm($this->formFactory, $data);
51
    }
52
53
    public function getSuccessRoute(): string
54
    {
55
        return $this->getRoute();
56
    }
57
58
    public function getSuccessRouteParameters(): array
59
    {
60
        return $this->getRouteParameters();
61
    }
62
63
    /**
64
     * Initialize Form. This form will be used in create and update actions.
65
     *
66
     * @param FormFactoryInterface $factory
67
     * @param mixed $data
68
     * @return FormInterface
69
     */
70
    abstract protected function initForm(FormFactoryInterface $factory, $data = null): FormInterface;
71
}
72