FormPass   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 32
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 4 1
A injectFormThemeConfiguration() 0 15 5
1
<?php
2
3
namespace Admingenerator\GeneratorBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
8
/**
9
 * Class FormCompilerPass
10
 * @package Admingenerator\GeneratorBundle\DependencyInjection\Compiler
11
 * @author Stéphane Escandell <[email protected]>
12
 */
13
class FormPass implements CompilerPassInterface
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function process(ContainerBuilder $container)
19
    {
20
        $this->injectFormThemeConfiguration($container);
21
    }
22
23
    /**
24
     * Check if we need to automatically add form theme from admingen in the
25
     * application configuration.
26
     *
27
     * @param ContainerBuilder $container
28
     */
29
    private function injectFormThemeConfiguration(ContainerBuilder $container)
30
    {
31
        if (($twigConfiguration = $container->getParameter('admingenerator.twig')) !== false) {
32
            $resources = $container->getParameter('twig.form.resources');
33
            $alreadyIn = in_array('bootstrap_3_layout.html.twig', $resources);
34
35
            if ($twigConfiguration['use_form_resources'] && !$alreadyIn) {
36
                $key = array_search('form_div_layout.html.twig', $resources) ? array_search('form_div_layout.html.twig', $resources) : 0;
37
                // Insert right after form_div_layout.html.twig if exists
38
                array_splice($resources, ++$key, 0, array('bootstrap_3_layout.html.twig'));
39
40
                $container->setParameter('twig.form.resources', $resources);
41
            }
42
        }
43
    }
44
}
45