add functionality
All checks were successful
build / build (pull_request) Successful in 5m29s

This commit is contained in:
2025-02-15 15:29:48 +01:00
parent deeadda315
commit bfe3ea37b5
5 changed files with 57 additions and 6 deletions

View File

@ -2,6 +2,7 @@
namespace App\Twig;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
@ -9,11 +10,22 @@ class Environment extends AbstractExtension
{
public function getFunctions(): array
{
return [new TwigFunction('env', $this->getVar(...))];
return [
new TwigFunction('env', $this->getVar(...)),
new TwigFunction('entityId', $this->getEntityId(...)),
];
}
public function getVar(string $name): string
{
return $_ENV[$name];
}
public function getEntityId(FieldDto $field): string
{
$url = $field->getCustomOption('toggleUrl');
preg_match('/entityId=(\d+)/', $url, $matches);
return $matches[1];
}
}