TokenProcessor.php in Rules 8.3
File
src/Plugin/RulesDataProcessor/TokenProcessor.php
View source
<?php
namespace Drupal\rules\Plugin\RulesDataProcessor;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\rules\Context\DataProcessorInterface;
use Drupal\rules\Context\ExecutionStateInterface;
use Drupal\typed_data\PlaceholderResolverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class TokenProcessor extends PluginBase implements DataProcessorInterface, ContainerFactoryPluginInterface {
protected $placeholderResolver;
public function __construct(array $configuration, $plugin_id, $plugin_definition, PlaceholderResolverInterface $placeholder_resolver) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->placeholderResolver = $placeholder_resolver;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('typed_data.placeholder_resolver'));
}
public function process($value, ExecutionStateInterface $rules_state) {
$data = [];
$placeholders_by_data = $this->placeholderResolver
->scan($value);
foreach ($placeholders_by_data as $variable_name => $placeholders) {
$data[$variable_name] = $rules_state
->getVariable($variable_name);
}
return $this->placeholderResolver
->replacePlaceHolders($value, $data);
}
}