[TWIG] Add extension to check if Firefox is being used

This commit is contained in:
2021-09-07 15:20:28 +01:00
committed by Hugo Sales
parent 0e50f0692e
commit ddd2ffe26a
3 changed files with 12 additions and 3 deletions

View File

@@ -58,6 +58,7 @@ class Extension extends AbstractExtension
new TwigFunction('handle_event', [Runtime::class, 'handleEvent']), new TwigFunction('handle_event', [Runtime::class, 'handleEvent']),
new TwigFunction('config', [Runtime::class, 'getConfig']), new TwigFunction('config', [Runtime::class, 'getConfig']),
new TwigFunction('icon', [Runtime::class, 'embedSvgIcon'], ['needs_environment' => true]), new TwigFunction('icon', [Runtime::class, 'embedSvgIcon'], ['needs_environment' => true]),
new TwigFunction('is_firefox', [Runtime::class, 'isFirefox']),
]; ];
} }
} }

View File

@@ -116,6 +116,12 @@ class Runtime implements RuntimeExtensionInterface, EventSubscriberInterface
return $twig->render('@public_path/assets/icons/' . $icon_name . '.svg.twig', ['iconClass' => $icon_css_class]); 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;
}
// ---------------------------------------------------------- // ----------------------------------------------------------
/** /**

View File

@@ -37,9 +37,11 @@
<br> <br>
<p> <p>
<em><b>Firefox based browser: </b> <kbd>Alt</kbd> + <kbd>Shift</kbd> + "access key"</em> {% if is_firefox() == true %}
<br> <em><kbd>Alt</kbd> + <kbd>Shift</kbd> + "access key"</em>
<em><b>Others: </b> <kbd>Alt</kbd> + "access key"</em> {% else %}
<em><kbd>Alt</kbd> + "access key"</em>
{% endif %}
</p> </p>
<ul> <ul>