From ddd2ffe26a5c89c91708d648b6c5f19635a76c07 Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Tue, 7 Sep 2021 15:20:28 +0100 Subject: [PATCH] [TWIG] Add extension to check if Firefox is being used --- src/Twig/Extension.php | 1 + src/Twig/Runtime.php | 6 ++++++ templates/base.html.twig | 8 +++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Twig/Extension.php b/src/Twig/Extension.php index 5501665190..d60329fbf7 100644 --- a/src/Twig/Extension.php +++ b/src/Twig/Extension.php @@ -58,6 +58,7 @@ class Extension extends AbstractExtension new TwigFunction('handle_event', [Runtime::class, 'handleEvent']), new TwigFunction('config', [Runtime::class, 'getConfig']), new TwigFunction('icon', [Runtime::class, 'embedSvgIcon'], ['needs_environment' => true]), + new TwigFunction('is_firefox', [Runtime::class, 'isFirefox']), ]; } } diff --git a/src/Twig/Runtime.php b/src/Twig/Runtime.php index 42e3676aef..bdba0717c9 100644 --- a/src/Twig/Runtime.php +++ b/src/Twig/Runtime.php @@ -116,6 +116,12 @@ class Runtime implements RuntimeExtensionInterface, EventSubscriberInterface return $twig->render('@public_path/assets/icons/' . $icon_name . '.svg.twig', ['iconClass' => $icon_css_class]); } + public function isFirefox(): bool + { + $re = '/.*(?i)\bfirefox\b.*/m'; + return preg_match(pattern: $re, subject: $this->request->headers->get('User-Agent')) === 1; + } + // ---------------------------------------------------------- /** diff --git a/templates/base.html.twig b/templates/base.html.twig index f1047d795d..895fd7f6e1 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -37,9 +37,11 @@

- Firefox based browser: Alt + Shift + "access key" -
- Others: Alt + "access key" + {% if is_firefox() == true %} + Alt + Shift + "access key" + {% else %} + Alt + "access key" + {% endif %}