Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(twig): Handle preview page of SyliusCmsPagePlugin render #243

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
Loading