You are here

protected function Engine::matchCondition in ThemeKey 8

Detects if a ThemeKey rule matches to the current page request.

Parameters

object $rule: ThemeKey rule as object:

  • property
  • operator
  • value

Return value

bool

1 call to Engine::matchCondition()
Engine::walkRuleChildren in src/Engine/Engine.php

File

src/Engine/Engine.php, line 103

Class

Engine

Namespace

Drupal\themekey\Engine

Code

protected function matchCondition(ThemeKeyRuleInterface $rule) {
  $operator = $this
    ->getOperatorManager()
    ->createInstance($rule
    ->operator());
  $property = $this
    ->getPropertyManager()
    ->createInstance($rule
    ->property());
  $property
    ->setEngine($this);

  #drupal_set_message(print_r($property->getValues(), TRUE));
  $values = $property
    ->getValues();
  $key = $rule
    ->key();
  if (!is_null($key)) {
    if (isset($values[$key])) {
      return $operator
        ->evaluate($values[$key], $rule
        ->value());
    }
  }
  else {
    foreach ($values as $value) {
      if ($operator
        ->evaluate($value, $rule
        ->value())) {
        return TRUE;
      }
    }
  }
  return FALSE;
}