The multiple choice and match question types allow the user to setup the question to use "simple scoring" or not.
The code in SimpleScoringResponseTrait.php does not correctly determine the status of the simple scoring flag and always follows the path as if it were NOT set.
The setScore function in the trait is passed the question entity and the code then checks to see if the question entity is an instanceof "SimpleScoringQuestionInterface". The issue is that the question entity never has this trait. The trait is set on the Question response Plugin Type classes (MatchingChoiceResponse, MultipleChoiceResponse) so the test will always fail.
The proposed solution is to modify the test in the trait so that the plugin instance is checked for the trait and then checked to see if the flag is checked or not.
/** @var \Drupal\quiz_maker\Entity\Question $question */
$question_plugin = $question->getPluginInstance();
$is_simple_score = $question_plugin instanceof SimpleScoringQuestionInterface ? $question_plugin->isSimpleScore() : FALSE;
In addition the SimpleScoringQuestionTrait.php needs to be changed as below so it checks for the existence and value of the simple scoring field on the question entity and not on the plugin which is what it is doing now.
public function isSimpleScore(): bool {
if ($this->entity instanceof Question && $this->entity->hasField('field_simple_scoring')) {
return (bool) $this->entity->get('field_simple_scoring')->getString();
}
return FALSE;
}
Active
1.0
Code