You are here

public function FillEntityVariableFields::getVariables in Business Rules 8

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

Return a variable set with all used variables on the item.

If you are using variables in a textfield, you can use the regex as the following:

preg_match_all(BusinessRulesItemPluginInterface::VARIABLE_REGEX, $text, $variables);

The $variables array will be filled with all used variables at index [1]

Parameters

\Drupal\business_rules\ItemInterface $item: The business rule item.

Return value

\Drupal\business_rules\VariablesSet The variableSet with all variables used on the Item.

Overrides BusinessRulesItemPluginBase::getVariables

File

src/Plugin/BusinessRulesAction/FillEntityVariableFields.php, line 370

Class

FillEntityVariableFields
Class FillEntityVariableFields.

Namespace

Drupal\business_rules\Plugin\BusinessRulesAction

Code

public function getVariables(ItemInterface $item) {
  $variableSet = new VariablesSet();
  $variable = new VariableObject($item
    ->getSettings('variable'));
  $variableSet
    ->append($variable);
  $fields_values_variables = $item
    ->getSettings('fields_values');
  if (is_array($fields_values_variables)) {
    foreach ($fields_values_variables as $fields_values_variable) {
      $field_value = $fields_values_variable['field_value'];
      $variable_names = $this
        ->pregMatch($field_value);
      if (is_array($variable_names)) {
        foreach ($variable_names as $variable_name) {
          $variable_name = explode('->', $variable_name)[0];
          $variable = new VariableObject($variable_name);
          $variableSet
            ->append($variable);
        }
      }
    }
  }
  return $variableSet;
}