From f3d69dc9feb7c934827782cf95eae5a3fa5acc0d Mon Sep 17 00:00:00 2001 From: yanniboi Date: Thu, 12 May 2016 19:50:18 -0400 Subject: [PATCH] Issue #2723259 by yanniboi: Added exceptions allowing single value fields to be passed to multiple context fields. --- src/Context/ContextHandlerIntegrityTrait.php | 5 ++++- src/Core/RulesActionBase.php | 6 +++++- src/Core/RulesConditionBase.php | 6 +++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Context/ContextHandlerIntegrityTrait.php b/src/Context/ContextHandlerIntegrityTrait.php index 4a0aba22..3a7eb786 100644 --- a/src/Context/ContextHandlerIntegrityTrait.php +++ b/src/Context/ContextHandlerIntegrityTrait.php @@ -134,7 +134,10 @@ protected function checkDataTypeCompatible(CoreContextDefinitionInterface $conte $target_type = $context_definition->getDataDefinition()->getDataType(); // Special case any and entity target types for now. - if ($target_type == 'any' || ($target_type == 'entity' && strpos($provided->getDataType(), 'entity:') !== FALSE)) { + if ($target_type == 'any' || + ($target_type == 'entity' && strpos($provided->getDataType(), 'entity:') !== FALSE) || + ($target_type == 'list' && $context_definition->isMultiple()) + ) { return; } if ($target_type != $provided->getDataType()) { diff --git a/src/Core/RulesActionBase.php b/src/Core/RulesActionBase.php index 1abb8930..ad700874 100644 --- a/src/Core/RulesActionBase.php +++ b/src/Core/RulesActionBase.php @@ -121,7 +121,11 @@ public function execute() { // passing the defined context as arguments. $args = []; foreach ($this->getContextDefinitions() as $name => $definition) { - $args[$name] = $this->getContextValue($name); + $value = $this->getContextValue($name); + if ($definition->isMultiple() && !is_array($value)) { + $value = [$value]; + } + $args[$name] = $value; } call_user_func_array([$this, 'doExecute'], $args); } diff --git a/src/Core/RulesConditionBase.php b/src/Core/RulesConditionBase.php index 9deaa9af..48e52e7a 100644 --- a/src/Core/RulesConditionBase.php +++ b/src/Core/RulesConditionBase.php @@ -64,7 +64,11 @@ public function evaluate() { // passing the defined context as arguments. $args = []; foreach ($this->getContextDefinitions() as $name => $definition) { - $args[$name] = $this->getContextValue($name); + $value = $this->getContextValue($name); + if ($definition->isMultiple() && !is_array($value)) { + $value = [$value]; + } + $args[$name] = $value; } return call_user_func_array([$this, 'doEvaluate'], $args); }