You are here

public function MobileDetectDeviceType::evaluate in Mobile Detect 8.2

Evaluates the condition and returns TRUE or FALSE accordingly.

Return value

bool TRUE if the condition has been met, FALSE otherwise.

Overrides ConditionInterface::evaluate

File

src/Plugin/Condition/MobileDetectDeviceType.php, line 98

Class

MobileDetectDeviceType
Provides a 'Device type' condition.

Namespace

Drupal\mobile_detect\Plugin\Condition

Code

public function evaluate() {
  $devices = $this->configuration['devices'];
  if (empty($devices) && !$this
    ->isNegated()) {
    return true;
  }
  $detect = $this->mobileDetect;
  foreach ($devices as $value) {
    if ($value == 'phone' && ($detect
      ->isMobile() && !$detect
      ->isTablet())) {
      return true;
    }
    if ($value == 'tablet' && $detect
      ->isTablet()) {
      return true;
    }
    if ($value == 'desktop' && !$detect
      ->isMobile()) {
      return true;
    }
  }
  return false;
}