4
4
5
5
use Symfony \Component \DependencyInjection \ContainerBuilder ;
6
6
use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
7
+ use Symfony \Component \HttpKernel \Kernel ;
7
8
8
9
/**
9
10
* Processes twig configuration
@@ -17,34 +18,25 @@ class FormCompilerPass implements CompilerPassInterface
17
18
*/
18
19
public function process (ContainerBuilder $ container )
19
20
{
21
+ // Used templates
22
+ $ templates = ['@AdmingeneratorFormExtensions/Form/form_html.html.twig ' ,
23
+ '@AdmingeneratorFormExtensions/Form/form_js.html.twig ' ,
24
+ '@AdmingeneratorFormExtensions/Form/form_css.html.twig ' ];
25
+
20
26
if (($ twigConfiguration = $ container ->getParameter ('admingenerator.form.twig ' )) !== false ) {
21
27
$ resources = $ container ->getParameter ('twig.form.resources ' );
22
- $ alreadyImported = in_array ('AdmingeneratorFormExtensionsBundle:Form:form_html.html.twig ' , $ resources )
23
- && in_array ('AdmingeneratorFormExtensionsBundle:Form:form_js.html.twig ' , $ resources )
24
- && in_array ('AdmingeneratorFormExtensionsBundle:Form:form_css.html.twig ' , $ resources );
28
+ $ alreadyImported = count (array_intersect ($ resources , $ templates )) == count ($ templates );
25
29
26
30
if ($ twigConfiguration ['use_form_resources ' ] && !$ alreadyImported ) {
27
31
if (($ key = array_search ('bootstrap_3_layout.html.twig ' , $ resources )) !== false ) {
28
32
// Insert right after bootstrap_3_layout.html.twig if exists
29
- array_splice ($ resources , ++$ key , 0 , array (
30
- 'AdmingeneratorFormExtensionsBundle:Form:form_html.html.twig ' ,
31
- 'AdmingeneratorFormExtensionsBundle:Form:form_js.html.twig ' ,
32
- 'AdmingeneratorFormExtensionsBundle:Form:form_css.html.twig '
33
- ));
33
+ array_splice ($ resources , ++$ key , 0 , $ templates );
34
34
} else if (($ key = array_search ('form_div_layout.html.twig ' , $ resources )) !== false ) {
35
35
// Insert right after form_div_layout.html.twig if exists
36
- array_splice ($ resources , ++$ key , 0 , array (
37
- 'AdmingeneratorFormExtensionsBundle:Form:form_html.html.twig ' ,
38
- 'AdmingeneratorFormExtensionsBundle:Form:form_js.html.twig ' ,
39
- 'AdmingeneratorFormExtensionsBundle:Form:form_css.html.twig '
40
- ));
36
+ array_splice ($ resources , ++$ key , 0 , $ templates );
41
37
} else {
42
38
// Put it in first position
43
- array_unshift ($ resources , array (
44
- 'AdmingeneratorFormExtensionsBundle:Form:form_html.html.twig ' ,
45
- 'AdmingeneratorFormExtensionsBundle:Form:form_js.html.twig ' ,
46
- 'AdmingeneratorFormExtensionsBundle:Form:form_css.html.twig '
47
- ));
39
+ array_unshift ($ resources , $ templates );
48
40
}
49
41
50
42
$ container ->setParameter ('twig.form.resources ' , $ resources );
0 commit comments