2023-08-07 19:20:14 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Core\Twig\Extension;
|
|
|
|
|
|
|
|
use App\Core\Entity\Site\Navigation;
|
|
|
|
use Twig\Extension\AbstractExtension;
|
|
|
|
use Twig\TwigFunction;
|
|
|
|
|
|
|
|
class NavigationExtension extends AbstractExtension
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getFunctions()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
new TwigFunction('navigation_color_badge', [$this, 'navigationColorBadge'], ['is_safe' => ['html']]),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function navigationColorBadge(Navigation $entity): ?string
|
|
|
|
{
|
|
|
|
if (!$entity->getColor()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sprintf(
|
2023-08-14 12:47:33 +02:00
|
|
|
'<span class="fa fa-square" style="color: %s"></span>',
|
2023-08-07 19:20:14 +02:00
|
|
|
$entity->getColor()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|