Skip to content

Commit 7f1f727

Browse files
jonathan1055jonathangreen
authored andcommitted
Issue #2824348 by dougmorin0, samuel.mortenson, jonathan1055, simonmc, jonathan.green: Warnings when using token replacements in multiple string context parameters
1 parent 63f87ed commit 7f1f727

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

src/Context/ContextHandlerTrait.php

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,40 @@ protected function assertMetadata(CoreContextAwarePluginInterface $plugin, Execu
288288
protected function processData(CoreContextAwarePluginInterface $plugin, ExecutionStateInterface $rules_state) {
289289
if (isset($this->configuration['context_processors'])) {
290290
foreach ($this->configuration['context_processors'] as $context_name => $processors) {
291+
$definition = $plugin->getContextDefinition($context_name);
291292
$value = $plugin->getContextValue($context_name);
292-
foreach ($processors as $processor_plugin_id => $configuration) {
293-
$data_processor = $this->processorManager->createInstance($processor_plugin_id, $configuration);
294-
$value = $data_processor->process($value, $rules_state);
293+
if ($definition->isMultiple()) {
294+
foreach ($value as &$current) {
295+
$current = $this->processValue($current, $processors, $rules_state);
296+
}
297+
}
298+
else {
299+
$value = $this->processValue($value, $processors, $rules_state);
295300
}
296301
$plugin->setContextValue($context_name, $value);
297302
}
298303
}
299304
}
300305

306+
/**
307+
* Processes a single value.
308+
*
309+
* @param mixed $value
310+
* The current value.
311+
* @param array $processors
312+
* An array mapping processor plugin IDs to their configuration.
313+
* @param \Drupal\rules\Engine\ExecutionStateInterface $rules_state
314+
* The current Rules execution state with context variables.
315+
*
316+
* @return mixed
317+
* THe processed value.
318+
*/
319+
protected function processValue($value, $processors, ExecutionStateInterface $rules_state) {
320+
foreach ($processors as $processor_plugin_id => $configuration) {
321+
$data_processor = $this->processorManager->createInstance($processor_plugin_id, $configuration);
322+
$value = $data_processor->process($value, $rules_state);
323+
}
324+
return $value;
325+
}
326+
301327
}

0 commit comments

Comments
 (0)