61 lines
1.6 KiB
PHP
61 lines
1.6 KiB
PHP
<?php
|
|
|
|
/*
|
|
* AVSDev UF Tweaks (https://avsdev.uk)
|
|
*
|
|
* @link https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks
|
|
* @license https://git.avsdev.uk/avsdev/sprinkle-uf-tweaks/blob/master/LICENSE.md (LGPL-3.0 License)
|
|
*/
|
|
|
|
namespace UserFrosting\Sprinkle\UFTweaks\Twig;
|
|
|
|
use Detection\MobileDetect;
|
|
use Psr\Container\ContainerInterface;
|
|
use Twig\Extension\AbstractExtension;
|
|
use Twig\Extension\GlobalsInterface;
|
|
use Twig\TwigFunction;
|
|
|
|
/**
|
|
* Extends Twig functionality for mobile detection.
|
|
*
|
|
* @author Craig Williams (https://avsdev.uk)
|
|
*/
|
|
class MobileDetectExtension extends AbstractExtension implements GlobalsInterface
|
|
{
|
|
/**
|
|
* @param ContainerInterface $services
|
|
*/
|
|
public function __construct(ContainerInterface $services)
|
|
{
|
|
}
|
|
|
|
public function getName()
|
|
{
|
|
return 'avsdev/uf-tweaks-mobileDetect';
|
|
}
|
|
|
|
public function getFunctions()
|
|
{
|
|
return [
|
|
// Add Twig function for checking permissions during dynamic menu rendering
|
|
new TwigFunction('isMobile', function () {
|
|
$detect = new MobileDetect();
|
|
return $detect->isMobile();
|
|
}),
|
|
new TwigFunction('isTablet', function () {
|
|
$detect = new MobileDetect();
|
|
return $detect->isTablet();
|
|
}),
|
|
new TwigFunction('isDesktop', function () {
|
|
$detect = new MobileDetect();
|
|
return !$detect->isTablet() && !$detect->isMobile();
|
|
}),
|
|
];
|
|
}
|
|
|
|
public function getGlobals()
|
|
{
|
|
return [];
|
|
}
|
|
}
|