function TokenProcessor::process

Overrides DataProcessorInterface::process

File

src/Plugin/RulesDataProcessor/TokenProcessor.php, line 61

Class

TokenProcessor
A data processor for placeholder token replacements.

Namespace

Drupal\rules\Plugin\RulesDataProcessor

Code

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);
}