You are here

public function UserCountry::evaluate in Smart IP 8.3

Same name and namespace in other branches
  1. 8.4 src/Plugin/Condition/UserCountry.php \Drupal\smart_ip\Plugin\Condition\UserCountry::evaluate()

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/UserCountry.php, line 90
Contains \Drupal\smart_ip\Plugin\Condition\UserCountry.

Class

UserCountry
Provides 'Countries' condition.

Namespace

Drupal\smart_ip\Plugin\Condition

Code

public function evaluate() {
  $countries = $this->configuration['countries'];
  if (empty($countries)) {
    return TRUE;
  }

  /** @var \Drupal\smart_ip\SmartIpLocation $location */
  $location = \Drupal::service('smart_ip.smart_ip_location');
  $userCountry = $location
    ->get('countryCode');
  if (empty($userCountry)) {

    // Can't identify visitor's location then show this block.
    return TRUE;
  }
  return (bool) isset($countries[$userCountry]) xor $this
    ->isNegated();
}