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 55namespace Codefog \HasteBundle \Twig ;
66
77use Codefog \HasteBundle \Formatter ;
8+ use Contao \CoreBundle \String \HtmlAttributes ;
9+ use Contao \CoreBundle \Twig \Runtime \BackendHelperRuntime ;
10+ use Contao \Image ;
811use Twig \Extension \AbstractExtension ;
912use Twig \TwigFunction ;
1013
@@ -16,9 +19,24 @@ public function __construct(private readonly Formatter $formatter)
1619
1720 public function getFunctions (): array
1821 {
19- return [
22+ $ functions = [
2023 new TwigFunction ('dca_label ' , $ this ->formatter ->dcaLabel (...)),
2124 new TwigFunction ('dca_value ' , $ this ->formatter ->dcaValue (...)),
2225 ];
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 ) : '' );
2341 }
2442}
You can’t perform that action at this time.
0 commit comments