Skip to content

Commit

Permalink
Use Sylius section to check if we are in admin or not
Browse files Browse the repository at this point in the history
  • Loading branch information
maximehuran committed Oct 2, 2024
1 parent 5bc4667 commit aa8de66
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/Twig/RichEditorExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -284,6 +286,9 @@ public function getMediaManagerFilePath(string $path): string
return $path;
}

/**
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
private function isAdmin(array $context): bool
{
/** @var ?AppVariable $app */
Expand All @@ -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;
}
}

0 comments on commit aa8de66

Please sign in to comment.