Skip to content

Commit 168a4c3

Browse files
authored
Merge pull request #243 from monsieurbiz/fix/preview-templates
fix(twig): Handle preview page of SyliusCmsPagePlugin render
2 parents a5e92de + aa8de66 commit 168a4c3

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/Twig/RichEditorExtension.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ final class RichEditorExtension extends AbstractExtension
3131
{
3232
private const ADMIN_FIREWALL_CONTEXT = 'security.firewall.map.context.admin';
3333

34+
private const SYLIUS_ADMIN_SECTION = 'admin';
35+
3436
private RegistryInterface $uiElementRegistry;
3537

3638
private Environment $twig;
@@ -284,6 +286,9 @@ public function getMediaManagerFilePath(string $path): string
284286
return $path;
285287
}
286288

289+
/**
290+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
291+
*/
287292
private function isAdmin(array $context): bool
288293
{
289294
/** @var ?AppVariable $app */
@@ -292,6 +297,19 @@ private function isAdmin(array $context): bool
292297
return false;
293298
}
294299

295-
return self::ADMIN_FIREWALL_CONTEXT === $request->get('_firewall_context');
300+
// Check Sylius section to know if we are in the admin
301+
/** @var ?array $sylius */
302+
$sylius = $request->get('_sylius');
303+
if (isset($sylius['section'])) {
304+
return self::SYLIUS_ADMIN_SECTION === $sylius['section'];
305+
}
306+
307+
// Check firewall context to know if we are in the admin
308+
if ($request->attributes->has('_firewall_context')) {
309+
return self::ADMIN_FIREWALL_CONTEXT === $request->attributes->get('_firewall_context');
310+
}
311+
312+
// False by default
313+
return false;
296314
}
297315
}

0 commit comments

Comments
 (0)