You are here

class IsMobileCacheContext in Mobile Detect 8.2

Defines the 'Is mobile' cache context.

Cache context ID: 'mobile_detect_is_mobile'.

Hierarchy

Expanded class hierarchy of IsMobileCacheContext

1 string reference to 'IsMobileCacheContext'
mobile_detect.services.yml in ./mobile_detect.services.yml
mobile_detect.services.yml
1 service uses IsMobileCacheContext
cache_context.mobile_detect_is_mobile in ./mobile_detect.services.yml
Drupal\mobile_detect\Cache\Context\IsMobileCacheContext

File

src/Cache/Context/IsMobileCacheContext.php, line 14

Namespace

Drupal\mobile_detect\Cache\Context
View source
class IsMobileCacheContext implements CacheContextInterface {

  /**
   * @var \Detection\MobileDetect
   */
  protected $mobileDetect;

  /**
   * Constructs an IsFrontPathCacheContext object.
   *
   * @param \Detection\MobileDetect $mobile_detect
   */
  public function __construct(MobileDetect $mobile_detect) {
    $this->mobileDetect = $mobile_detect;
  }

  /**
   * {@inheritdoc}
   */
  public static function getLabel() {
    return 'Is mobile';
  }

  /**
   * {@inheritdoc}
   */
  public function getContext() {
    return (string) $this->mobileDetect
      ->isMobile();
  }

  /**
   * {@inheritdoc}
   */
  public function getCacheableMetadata() {
    return new CacheableMetadata();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
IsMobileCacheContext::$mobileDetect protected property
IsMobileCacheContext::getCacheableMetadata public function Gets the cacheability metadata for the context. Overrides CacheContextInterface::getCacheableMetadata
IsMobileCacheContext::getContext public function Returns the string representation of the cache context. Overrides CacheContextInterface::getContext
IsMobileCacheContext::getLabel public static function Returns the label of the cache context. Overrides CacheContextInterface::getLabel
IsMobileCacheContext::__construct public function Constructs an IsFrontPathCacheContext object.