<?php
namespace App\Twig;
use App\Entity\SettingsBranding;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Twig\Extension\AbstractExtension;
use Twig\Extension\GlobalsInterface;
class BrandingExtension extends AbstractExtension implements GlobalsInterface
{
private $em;
private $requestStack;
public function __construct(EntityManagerInterface $em, RequestStack $requestStack)
{
$this->em = $em;
$this->requestStack = $requestStack;
}
public function getGlobals(): array
{
$request = $this->requestStack->getCurrentRequest();
if (!$request) {
return ['branding_current' => null];
}
$session = $request->getSession();
$accessType = $session ? $session->get('current_access_type', 'venues') : 'venues';
$branding = $this->em
->getRepository(SettingsBranding::class)
->findOneBy(['accessType' => $accessType]);
return [
'branding_current' => $branding,
];
}
}