You are here

public function BusinessRulesItemPluginBase::processVariables in Business Rules 2.x

Same name and namespace in other branches
  1. 8 src/Plugin/BusinessRulesItemPluginBase.php \Drupal\business_rules\Plugin\BusinessRulesItemPluginBase::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 BusinessRulesItemPluginInterface::processVariables

30 calls to BusinessRulesItemPluginBase::processVariables()
AddNodeToGroupAction::execute in modules/br_group/src/Plugin/BusinessRulesAction/AddNodeToGroupAction.php
Execute the action.
AddRoleToUser::execute in src/Plugin/BusinessRulesAction/AddRoleToUser.php
Execute the action.
AddUserToGroupAction::execute in modules/br_group/src/Plugin/BusinessRulesAction/AddUserToGroupAction.php
Execute the action.
AssignRoleToUserAction::execute in modules/br_group/src/Plugin/BusinessRulesAction/AssignRoleToUserAction.php
Execute the action.
BusinessRulesItemPluginBase::processTokenArraySetting in src/Plugin/BusinessRulesItemPluginBase.php
Helper function to process tokens if the setting is an array.

... See full list

1 method overrides BusinessRulesItemPluginBase::processVariables()
SetFieldValue::processVariables in src/Plugin/BusinessRulesAction/SetFieldValue.php
Process the item replacing the variables by it's values.

File

src/Plugin/BusinessRulesItemPluginBase.php, line 149

Class

BusinessRulesItemPluginBase
Base Class for Business rules plugins.

Namespace

Drupal\business_rules\Plugin

Code

public function processVariables($content, VariablesSet $event_variables) {

  /** @var \Drupal\business_rules\VariableObject $variable */
  if ($event_variables
    ->count()) {
    foreach ($event_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();
          }
          elseif (stristr($content, '{{' . $variable
            ->getId() . '}}')) {
            $value = implode(chr(10), $variable
              ->getValue());
            $content = str_replace('{{' . $variable
              ->getId() . '}}', $value, $content);
          }
        }
      }
      elseif (empty($variable
        ->getValue())) {
        $content = str_replace('{{' . $variable
          ->getId() . '}}', 'NULL', $content);
      }
    }
  }
  return $content;
}