You are here

public function RequestDomain::evaluate in Context 8.4

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/RequestDomain.php, line 106

Class

RequestDomain
Provides a 'Request domain' condition.

Namespace

Drupal\context\Plugin\Condition

Code

public function evaluate() {

  // Convert domain to lowercase.
  $domains = mb_strtolower($this->configuration['domains']);
  if (!$domains) {
    return TRUE;
  }

  // Domain array.
  $domains = array_map('trim', explode("\n", $this->configuration['domains']));

  // Takes the current host.
  $request = $this->requestStack
    ->getCurrentRequest();
  $host = $request
    ->getHost();
  if (empty($host)) {
    return FALSE;
  }
  if (in_array($host, $domains)) {
    return TRUE;
  }
  return FALSE;
}