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

This commit is contained in:
Diogo Peralta Cordeiro 2021-09-07 15:20:28 +01:00 committed by Hugo Sales
parent 0e50f0692e
commit ddd2ffe26a
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
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('config', [Runtime::class, 'getConfig']),
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]);
}
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>
<p>
<em><b>Firefox based browser: </b> <kbd>Alt</kbd> + <kbd>Shift</kbd> + "access key"</em>
<br>
<em><b>Others: </b> <kbd>Alt</kbd> + "access key"</em>
{% if is_firefox() == true %}
<em><kbd>Alt</kbd> + <kbd>Shift</kbd> + "access key"</em>
{% else %}
<em><kbd>Alt</kbd> + "access key"</em>
{% endif %}
</p>
<ul>