From aa8de66fbf1668ec55d1777b24587b3832dfa6df Mon Sep 17 00:00:00 2001 From: Maxime Huran Date: Wed, 2 Oct 2024 14:41:13 +0200 Subject: [PATCH] Use Sylius section to check if we are in admin or not --- src/Twig/RichEditorExtension.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Twig/RichEditorExtension.php b/src/Twig/RichEditorExtension.php index 885b3cc7..ed3a8cbc 100644 --- a/src/Twig/RichEditorExtension.php +++ b/src/Twig/RichEditorExtension.php @@ -31,6 +31,8 @@ final class RichEditorExtension extends AbstractExtension { private const ADMIN_FIREWALL_CONTEXT = 'security.firewall.map.context.admin'; + private const SYLIUS_ADMIN_SECTION = 'admin'; + private RegistryInterface $uiElementRegistry; private Environment $twig; @@ -284,6 +286,9 @@ public function getMediaManagerFilePath(string $path): string return $path; } + /** + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + */ private function isAdmin(array $context): bool { /** @var ?AppVariable $app */ @@ -292,11 +297,19 @@ private function isAdmin(array $context): bool return false; } - // If we are on the SyliusCmsPagePlugin preview page, we need to load Shop templates. - if ('monsieurbiz_cms_page_admin_page_preview' === $request->get('_route')) { - return false; + // Check Sylius section to know if we are in the admin + /** @var ?array $sylius */ + $sylius = $request->get('_sylius'); + if (isset($sylius['section'])) { + return self::SYLIUS_ADMIN_SECTION === $sylius['section']; + } + + // Check firewall context to know if we are in the admin + if ($request->attributes->has('_firewall_context')) { + return self::ADMIN_FIREWALL_CONTEXT === $request->attributes->get('_firewall_context'); } - return self::ADMIN_FIREWALL_CONTEXT === $request->get('_firewall_context'); + // False by default + return false; } }