33namespace EasyCorp \Bundle \EasyAdminBundle \Twig ;
44
55use EasyCorp \Bundle \EasyAdminBundle \Collection \FieldCollection ;
6+ use EasyCorp \Bundle \EasyAdminBundle \Contracts \Context \AdminContextInterface ;
67use EasyCorp \Bundle \EasyAdminBundle \Contracts \Provider \AdminContextProviderInterface ;
78use EasyCorp \Bundle \EasyAdminBundle \Dto \FieldLayoutDto ;
89use EasyCorp \Bundle \EasyAdminBundle \Factory \FormLayoutFactory ;
@@ -45,6 +46,7 @@ public function __construct(
4546 public function getFunctions (): array
4647 {
4748 return [
49+ new TwigFunction ('ea ' , [$ this , 'ea ' ]),
4850 new TwigFunction ('ea_url ' , [$ this , 'getAdminUrlGenerator ' ]),
4951 new TwigFunction ('ea_form_ealabel ' , null , ['node_class ' => 'Symfony\Bridge\Twig\Node\SearchAndRenderBlockNode ' , 'is_safe ' => ['html ' ]]),
5052 // deprecated functions
@@ -69,10 +71,14 @@ public function getFilters(): array
6971
7072 public function getGlobals (): array
7173 {
72- // this is needed to make the admin context available on any Twig template via the short named variable 'ea'
7374 return ['ea ' => $ this ->adminContextProvider ];
7475 }
7576
77+ public function ea (): ?AdminContextInterface
78+ {
79+ return $ this ->adminContextProvider ->getContext ();
80+ }
81+
7682 /**
7783 * Transforms ['a' => 'foo', 'b' => ['c' => ['d' => 7]]] into ['a' => 'foo', 'b[c][d]' => 7]
7884 * It's useful to submit nested arrays (e.g. query string parameters) as form fields.
0 commit comments