You are here

public function BusinessRulesItemPluginBase::processTokens in Business Rules 8

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

Process the tokens on the settings property for the item.

Parameters

\Drupal\business_rules\ItemInterface $item: The Business Rules item.

\Drupal\business_rules\Events\BusinessRulesEvent $event: The BusinessRulesEvent that triggered the processor.

Overrides BusinessRulesItemPluginInterface::processTokens

File

src/Plugin/BusinessRulesItemPluginBase.php, line 179

Class

BusinessRulesItemPluginBase
Base Class for Business rules plugins.

Namespace

Drupal\business_rules\Plugin

Code

public function processTokens(ItemInterface &$item, BusinessRulesEvent $event) {
  $settings = $item
    ->getSettings();

  // Get the context entity to pass to token processor.
  try {
    $entity_type = $event
      ->getArgument('entity_type_id');
    $entity = $event
      ->getArgument('entity');
    $context = [
      $entity_type => $entity,
    ];
  } catch (\InvalidArgumentException $e) {
    $context = [];
  }
  foreach ($settings as $key => $setting) {
    if (is_string($setting)) {
      $variables = $event
        ->getArgument('variables');
      $setting = $this
        ->processVariables($setting, $variables);
      $settings[$key] = $this->util->token
        ->replace($setting, $context, [
        'clear' => TRUE,
      ]);
    }
    elseif (is_array($setting)) {
      $this
        ->processTokenArraySetting($settings[$key], $context, $event);
    }
  }
  foreach ($settings as $key => $setting) {
    $item
      ->setSetting($key, $setting);
  }
}