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,23 +18,19 @@ class FormCompilerPass implements CompilerPassInterface
17
18
*/
18
19
public function process (ContainerBuilder $ container )
19
20
{
21
+ // Used templates
22
+ $ templates = ['@AdmingeneratorForm/form_js.html.twig ' , '@AdmingeneratorForm/form_css.html.twig ' ];
23
+
20
24
$ resources = $ container ->getParameter ('twig.form.resources ' );
21
- $ alreadyImported = in_array ('AdmingeneratorFormBundle::form_js.html.twig ' , $ resources )
22
- && in_array ('AdmingeneratorFormBundle::form_css.html.twig ' , $ resources );
25
+ $ alreadyImported = count (array_intersect ($ resources , $ templates )) == count ($ templates );
23
26
24
27
if (!$ alreadyImported ) {
25
28
// Insert right after form_div_layout.html.twig if exists
26
29
if (($ key = array_search ('form_div_layout.html.twig ' , $ resources )) !== false ) {
27
- array_splice ($ resources , ++$ key , 0 , array (
28
- 'AdmingeneratorFormBundle::form_js.html.twig ' ,
29
- 'AdmingeneratorFormBundle::form_css.html.twig '
30
- ));
30
+ array_splice ($ resources , ++$ key , 0 , $ templates );
31
31
} else {
32
32
// Put it in first position
33
- array_unshift ($ resources , array (
34
- 'AdmingeneratorFormBundle::form_js.html.twig ' ,
35
- 'AdmingeneratorFormBundle::form_css.html.twig '
36
- ));
33
+ array_unshift ($ resources , $ templates );
37
34
}
38
35
39
36
$ container ->setParameter ('twig.form.resources ' , $ resources );
0 commit comments