IsMobileCacheContext.php in Mobile Detect 8.2
File
src/Cache/Context/IsMobileCacheContext.php
View source
<?php
namespace Drupal\mobile_detect\Cache\Context;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Cache\Context\CacheContextInterface;
use Detection\MobileDetect;
class IsMobileCacheContext implements CacheContextInterface {
protected $mobileDetect;
public function __construct(MobileDetect $mobile_detect) {
$this->mobileDetect = $mobile_detect;
}
public static function getLabel() {
return 'Is mobile';
}
public function getContext() {
return (string) $this->mobileDetect
->isMobile();
}
public function getCacheableMetadata() {
return new CacheableMetadata();
}
}