12
12
use Psr \Container \ContainerInterface ;
13
13
use Symfony \WebpackEncoreBundle \Asset \EntrypointLookupInterface ;
14
14
use Symfony \WebpackEncoreBundle \Asset \TagRenderer ;
15
+ use Symfony \WebpackEncoreBundle \Exception \EntrypointNotFoundException ;
15
16
use Twig \Extension \AbstractExtension ;
16
17
use Twig \TwigFunction ;
17
18
@@ -29,6 +30,8 @@ public function getFunctions(): array
29
30
return [
30
31
new TwigFunction ('encore_entry_js_files ' , [$ this , 'getWebpackJsFiles ' ]),
31
32
new TwigFunction ('encore_entry_css_files ' , [$ this , 'getWebpackCssFiles ' ]),
33
+ new TwigFunction ('encore_has_entry_js_files ' , [$ this , 'hasWebpackJsFiles ' ]),
34
+ new TwigFunction ('encore_has_entry_css_files ' , [$ this , 'hasWebpackCssFiles ' ]),
32
35
new TwigFunction ('encore_entry_script_tags ' , [$ this , 'renderWebpackScriptTags ' ], ['is_safe ' => ['html ' ]]),
33
36
new TwigFunction ('encore_entry_link_tags ' , [$ this , 'renderWebpackLinkTags ' ], ['is_safe ' => ['html ' ]]),
34
37
];
@@ -46,6 +49,30 @@ public function getWebpackCssFiles(string $entryName, string $entrypointName = '
46
49
->getCssFiles ($ entryName );
47
50
}
48
51
52
+ public function hasWebpackJsFiles (string $ entryName , string $ entrypointName = '_default ' ): bool
53
+ {
54
+ try {
55
+ $ entrypointLookup = $ this ->getEntrypointLookup ($ entrypointName );
56
+ $ entrypointLookup ->reset ();
57
+
58
+ return count ($ entrypointLookup ->getJavaScriptFiles ($ entryName )) > 0 ;
59
+ } catch (EntrypointNotFoundException $ e ) {
60
+ return false ;
61
+ }
62
+ }
63
+
64
+ public function hasWebpackCssFiles (string $ entryName , string $ entrypointName = '_default ' ): bool
65
+ {
66
+ try {
67
+ $ entrypointLookup = $ this ->getEntrypointLookup ($ entrypointName );
68
+ $ entrypointLookup ->reset ();
69
+
70
+ return count ($ entrypointLookup ->getCssFiles ($ entryName )) > 0 ;
71
+ } catch (EntrypointNotFoundException $ e ) {
72
+ return false ;
73
+ }
74
+ }
75
+
49
76
public function renderWebpackScriptTags (string $ entryName , string $ packageName = null , string $ entrypointName = '_default ' , array $ attributes = []): string
50
77
{
51
78
return $ this ->getTagRenderer ()
0 commit comments