Skip to content

Commit

Permalink
Fix clashing global twig variable
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Dec 8, 2023
1 parent 4f71371 commit 25e6b40
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/Controller/CRUDController.php
Original file line number Diff line number Diff line change
Expand Up @@ -994,18 +994,15 @@ final public function configureAdmin(Request $request): void
*/
final public function setTwigGlobals(Request $request): void
{
$twig = $this->container->get('twig');
\assert($twig instanceof Environment);

$twig->addGlobal('admin', $this->admin);
$this->setTwigGlobal('admin', $this->admin);

if ($this->isXmlHttpRequest($request)) {
$baseTemplate = $this->templateRegistry->getTemplate('ajax');
} else {
$baseTemplate = $this->templateRegistry->getTemplate('layout');
}

$twig->addGlobal('base_template', $baseTemplate);
$this->setTwigGlobal('base_template', $baseTemplate);
}

/**
Expand Down Expand Up @@ -1543,6 +1540,18 @@ final protected function checkParentChildAssociation(Request $request, object $o
}
}

private function setTwigGlobal(string $name, mixed $value): void
{
$twig = $this->container->get('twig');
\assert($twig instanceof Environment);

try {
$twig->addGlobal($name, $value);
} catch (\LogicException) {
// Variable already set
}
}

private function getBatchActionExecutable(string $action): callable
{
$batchActions = $this->admin->getBatchActions();
Expand Down

0 comments on commit 25e6b40

Please sign in to comment.