Skip to content

Commit

Permalink
Merge pull request #243 from monsieurbiz/fix/preview-templates
Browse files Browse the repository at this point in the history
fix(twig): Handle preview page of SyliusCmsPagePlugin render
  • Loading branch information
maximehuran authored Oct 2, 2024
2 parents a5e92de + aa8de66 commit 168a4c3
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion 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,6 +297,19 @@ private function isAdmin(array $context): bool
return false;
}

return self::ADMIN_FIREWALL_CONTEXT === $request->get('_firewall_context');
// 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');
}

// False by default
return false;
}
}

0 comments on commit 168a4c3

Please sign in to comment.