public function TokenProcessor::process in Rules 8.3
Process the given value.
Parameters
mixed $value: The value to process.
\Drupal\rules\Context\ExecutionStateInterface $rules_state: The current Rules execution state containing all context variables.
Return value
mixed The processed value. Since the value can also be a primitive data type (a string for example) this function must return the value.
Throws
\Drupal\rules\Exception\EvaluationException Thrown when the data cannot be processed.
Overrides DataProcessorInterface::process
File
- src/
Plugin/ RulesDataProcessor/ TokenProcessor.php, line 61
Class
- TokenProcessor
- A data processor for placeholder token replacements.
Namespace
Drupal\rules\Plugin\RulesDataProcessorCode
public function process($value, ExecutionStateInterface $rules_state) {
$data = [];
$placeholders_by_data = $this->placeholderResolver
->scan($value);
foreach ($placeholders_by_data as $variable_name => $placeholders) {
// Note that accessing an unavailable variable will throw an evaluation
// exception. That's exactly what needs to happen. Invalid tokens must
// be detected when checking integrity. The Rule must not be executed
// if the integrity check fails. Runtime is too late to handle
// invalid tokens gracefully.
$data[$variable_name] = $rules_state
->getVariable($variable_name);
}
return $this->placeholderResolver
->replacePlaceHolders($value, $data);
}