You are here

public function UrlVariable::evaluate in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Plugin/BusinessRulesVariable/UrlVariable.php \Drupal\business_rules\Plugin\BusinessRulesVariable\UrlVariable::evaluate()

Evaluate the variable.

Parameters

\Drupal\business_rules\Entity\Variable $variable: The variable to be evaluated.

\Drupal\business_rules\Events\BusinessRulesEvent $event: The dispatched event.

Return value

\Drupal\business_rules\VariableObject|\Drupal\business_rules\VariablesSet The evaluated variables.

Overrides BusinessRulesVariablePlugin::evaluate

File

src/Plugin/BusinessRulesVariable/UrlVariable.php, line 117

Class

UrlVariable
A variable representing the current url.

Namespace

Drupal\business_rules\Plugin\BusinessRulesVariable

Code

public function evaluate(Variable $variable, BusinessRulesEvent $event) {
  $url = $_SERVER['REQUEST_URI'];
  $variableObject = new VariableObject($variable
    ->id(), $url, $variable
    ->getType());
  $variableSet = new VariablesSet();
  $variableSet
    ->append($variableObject);
  $parts = explode('/', $url);
  foreach ($parts as $key => $part) {
    $variableObject = new VariableObject($variable
      ->id() . '->' . $key, $part, $variable
      ->getType());
    $variableSet
      ->append($variableObject);
  }
  return $variableSet;
}