Skip to content

Commit d17b48f

Browse files
committed
Add BC for the backend_icon Twig helper
1 parent 8e9ad21 commit d17b48f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/Twig/HasteExtension.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
namespace Codefog\HasteBundle\Twig;
66

77
use Codefog\HasteBundle\Formatter;
8+
use Contao\CoreBundle\String\HtmlAttributes;
9+
use Contao\CoreBundle\Twig\Runtime\BackendHelperRuntime;
10+
use Contao\Image;
811
use Twig\Extension\AbstractExtension;
912
use 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
}

0 commit comments

Comments
 (0)