class MobileDetectTwig in Mobile Detect 8.2
MobileDetectTwig class.
Hierarchy
- class \Drupal\mobile_detect\Twig\MobileDetectTwig extends \Twig\Extension\AbstractExtension
Expanded class hierarchy of MobileDetectTwig
1 string reference to 'MobileDetectTwig'
1 service uses MobileDetectTwig
File
- src/
Twig/ MobileDetectTwig.php, line 13
Namespace
Drupal\mobile_detect\TwigView source
class MobileDetectTwig extends AbstractExtension {
/**
* Mobile detect service.
*
* @var \Detection\MobileDetect
*/
protected $mobileDetector;
/**
* Constructor
* @param MobileDetect $mobileDetector
*/
public function __construct(MobileDetect $mobileDetector) {
$this->mobileDetector = $mobileDetector;
}
/**
* Get extension twig function
* @return array
*/
public function getFunctions() {
return [
new TwigFunction('is_mobile', [
$this,
'isMobile',
]),
new TwigFunction('is_tablet', [
$this,
'isTablet',
]),
new TwigFunction('is_device', [
$this,
'isDevice',
]),
new TwigFunction('is_ios', [
$this,
'isIOS',
]),
new TwigFunction('is_android_os', [
$this,
'isAndroidOS',
]),
];
}
/**
* Is mobile
* @return boolean
*/
public function isMobile() {
return $this->mobileDetector
->isMobile();
}
/**
* Is tablet
* @return boolean
*/
public function isTablet() {
return $this->mobileDetector
->isTablet();
}
/**
* Is device
* @param string $deviceName is[iPhone|BlackBerry|HTC|Nexus|Dell|Motorola|Samsung|Sony|Asus|Palm|Vertu|...]
* @return boolean
*/
public function isDevice($deviceName) {
$methodName = 'is' . strtolower((string) $deviceName);
return $this->mobileDetector
->{$methodName}();
}
/**
* Is iOS
* @return boolean
*/
public function isIOS() {
return $this->mobileDetector
->isIOS();
}
/**
* Is Android OS
* @return boolean
*/
public function isAndroidOS() {
return $this->mobileDetector
->isAndroidOS();
}
/**
* Extension name
* @return string
*/
public function getName() {
return 'mobile_detect.twig.extension';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MobileDetectTwig:: |
protected | property | Mobile detect service. | |
MobileDetectTwig:: |
public | function | * Get extension twig function * | |
MobileDetectTwig:: |
public | function | * Extension name * | |
MobileDetectTwig:: |
public | function | * Is Android OS * | |
MobileDetectTwig:: |
public | function | * Is device * | |
MobileDetectTwig:: |
public | function | * Is iOS * | |
MobileDetectTwig:: |
public | function | * Is mobile * | |
MobileDetectTwig:: |
public | function | * Is tablet * | |
MobileDetectTwig:: |
public | function | * Constructor * |