You are here

public function SetFieldValue::processVariables in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Plugin/BusinessRulesAction/SetFieldValue.php \Drupal\business_rules\Plugin\BusinessRulesAction\SetFieldValue::processVariables()

Process the item replacing the variables by it's values.

Parameters

mixed $content: The item to be replaced by the variable value.

\Drupal\business_rules\VariablesSet $event_variables: Array of Variables provided by the event.

Return value

mixed The processed content, replacing the variables tokens for it's values.

Overrides BusinessRulesItemPluginBase::processVariables

1 call to SetFieldValue::processVariables()
SetFieldValue::execute in src/Plugin/BusinessRulesAction/SetFieldValue.php
Execute the action.

File

src/Plugin/BusinessRulesAction/SetFieldValue.php, line 110

Class

SetFieldValue
Class SetFieldValue.

Namespace

Drupal\business_rules\Plugin\BusinessRulesAction

Code

public function processVariables($content, VariablesSet $variables) {
  if ($variables
    ->count()) {
    foreach ($variables
      ->getVariables() as $variable) {
      if (is_string($variable
        ->getValue()) || is_numeric($variable
        ->getValue())) {
        $content = str_replace('{{' . $variable
          ->getId() . '}}', $variable
          ->getValue(), $content);
      }
      elseif (is_array($variable
        ->getValue())) {
        if (preg_match_all(self::VARIABLE_REGEX, $content)) {
          if ($content == '{{' . $variable
            ->getId() . '}}') {
            $content = $variable
              ->getValue();
          }
        }
      }
    }
  }
  return $content;
}