File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 5
5
namespace Codefog \HasteBundle \Twig ;
6
6
7
7
use Codefog \HasteBundle \Formatter ;
8
+ use Contao \CoreBundle \String \HtmlAttributes ;
9
+ use Contao \CoreBundle \Twig \Runtime \BackendHelperRuntime ;
10
+ use Contao \Image ;
8
11
use Twig \Extension \AbstractExtension ;
9
12
use Twig \TwigFunction ;
10
13
@@ -16,9 +19,24 @@ public function __construct(private readonly Formatter $formatter)
16
19
17
20
public function getFunctions (): array
18
21
{
19
- return [
22
+ $ functions = [
20
23
new TwigFunction ('dca_label ' , $ this ->formatter ->dcaLabel (...)),
21
24
new TwigFunction ('dca_value ' , $ this ->formatter ->dcaValue (...)),
22
25
];
26
+
27
+ if (!class_exists (BackendHelperRuntime::class)) {
28
+ $ functions [] = new TwigFunction (
29
+ 'backend_icon ' ,
30
+ $ this ->generateIcon (...),
31
+ ['is_safe ' => ['html ' ]],
32
+ );
33
+ }
34
+
35
+ return $ functions ;
36
+ }
37
+
38
+ private function generateIcon (string $ src , string $ alt = '' , HtmlAttributes |null $ attributes = null ): string
39
+ {
40
+ return Image::getHtml ($ src , $ alt , $ attributes ? $ attributes ->toString (false ) : '' );
23
41
}
24
42
}
You can’t perform that action at this time.
0 commit comments