Loading src/Plugin/WebformScore/Maximum.php +13 −3 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Drupal\webform_score\Plugin\WebformScore; use Drupal\Core\TypedData\TypedDataInterface; use Drupal\Core\TypedData\TraversableTypedDataInterface; /** * Score is based on the maximum value from a set of scores. Loading Loading @@ -31,12 +32,21 @@ class Maximum extends WebformScoreAggregateBase { /** * {@inheritdoc} */ public function score(TypedDataInterface $answer) { public function score(TypedDataInterface $answers) { $scores = []; $plugins = $this->createPlugins(); foreach ($this->createPlugins() as $plugin) { if (!($answers instanceof TraversableTypedDataInterface)) { // If the answers are not in traversable format, convert them in an array // so that further logic can work correctly. $answers = [$answers]; } foreach ($answers as $answer) { foreach ($plugins as $plugin) { $scores[] = $plugin->score($answer); } } return max($scores); } Loading Loading
src/Plugin/WebformScore/Maximum.php +13 −3 Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Drupal\webform_score\Plugin\WebformScore; use Drupal\Core\TypedData\TypedDataInterface; use Drupal\Core\TypedData\TraversableTypedDataInterface; /** * Score is based on the maximum value from a set of scores. Loading Loading @@ -31,12 +32,21 @@ class Maximum extends WebformScoreAggregateBase { /** * {@inheritdoc} */ public function score(TypedDataInterface $answer) { public function score(TypedDataInterface $answers) { $scores = []; $plugins = $this->createPlugins(); foreach ($this->createPlugins() as $plugin) { if (!($answers instanceof TraversableTypedDataInterface)) { // If the answers are not in traversable format, convert them in an array // so that further logic can work correctly. $answers = [$answers]; } foreach ($answers as $answer) { foreach ($plugins as $plugin) { $scores[] = $plugin->score($answer); } } return max($scores); } Loading