diff --git a/mod/quiz/classes/output/edit_renderer.php b/mod/quiz/classes/output/edit_renderer.php index fe99fd5a1bb..d17d33ef264 100644 --- a/mod/quiz/classes/output/edit_renderer.php +++ b/mod/quiz/classes/output/edit_renderer.php @@ -924,7 +924,7 @@ class edit_renderer extends \plugin_renderer_base { public function question_preview_icon($quiz, $questiondata, $label = null, $variant = null, $restartversion = null) { $question = clone($questiondata); - if (!\question_bank::is_question_valid($question)) { + if (!\question_bank::is_qtype_usable($question->qtype)) { return ''; } diff --git a/mod/quiz/classes/question/bank/preview_action_column.php b/mod/quiz/classes/question/bank/preview_action_column.php index e918b9f1b6f..74261d6b3a9 100644 --- a/mod/quiz/classes/question/bank/preview_action_column.php +++ b/mod/quiz/classes/question/bank/preview_action_column.php @@ -52,7 +52,7 @@ class preview_action_column extends \core_question\local\bank\column_base { if (!question_has_capability_on($question, 'use')) { return; } - if (!\question_bank::is_question_valid($question)) { + if (!\question_bank::is_qtype_usable($question->qtype)) { return; } $editrenderer = $PAGE->get_renderer('quiz', 'edit'); diff --git a/question/bank/viewquestionname/classes/question_name_idnumber_tags_column.php b/question/bank/viewquestionname/classes/question_name_idnumber_tags_column.php index 099c2148041..97063dc5980 100644 --- a/question/bank/viewquestionname/classes/question_name_idnumber_tags_column.php +++ b/question/bank/viewquestionname/classes/question_name_idnumber_tags_column.php @@ -63,7 +63,7 @@ class question_name_idnumber_tags_column extends viewquestionname_column_helper echo \html_writer::end_tag('div'); // If the question is invalid, show a warning badge. - if (!\question_bank::is_question_valid($question)) { + if (!\question_bank::is_qtype_usable($question->qtype)) { echo \html_writer::span(get_string('invalidquestiontype', 'question', $question->qtype), 'badge bg-danger text-white'); } diff --git a/question/classes/local/bank/view.php b/question/classes/local/bank/view.php index 81801479f1f..9161822682a 100644 --- a/question/classes/local/bank/view.php +++ b/question/classes/local/bank/view.php @@ -1532,7 +1532,7 @@ class view { $attributes = []; // If the question type is invalid we highlight it red. - if (!\question_bank::is_question_valid($question)) { + if (!\question_bank::is_qtype_usable($question->qtype)) { $rowclasses .= ' table-danger'; } if ($rowclasses) { diff --git a/question/engine/bank.php b/question/engine/bank.php index 5f6794dacbb..0d450f4e1c9 100644 --- a/question/engine/bank.php +++ b/question/engine/bank.php @@ -83,6 +83,23 @@ abstract class question_bank { return $plugindir && is_readable($plugindir . '/questiontype.php'); } + /** + * Check if a given question type is one that is installed and usable. + * + * Use this before doing things like rendering buttons/options which will only work for + * installed question types. + * + * When loaded through most of the core_question areas, qtype will still be the uninstalled type, e.g. 'mytype', + * but when we get to the quiz pages, it will have been converted to 'missingtype'. So we need to check that + * as well here. + * + * @param string $qtypename e.g. 'multichoice'. + * @return bool + */ + public static function is_qtype_usable(string $qtypename): bool { + return self::is_qtype_installed($qtypename) && $qtypename !== 'missingtype'; + } + /** * Get the question type class for a particular question type. * @param string $qtypename the question type name. For example 'multichoice' or 'shortanswer'. @@ -506,23 +523,6 @@ abstract class question_bank { $qtypes = $DB->get_fieldset_sql($sql, $params); return $qtypes; } - - /** - * Check if a given question is valid. - * This is used in places where we want to do things like render buttons/options which will only work for - * valid, installed question types. - * - * When loaded through most of the core_question areas, qtype will still be the uninstalled type, e.g. 'mytype', - * but when we get to the quiz pages, it will have been converted to 'missingtype'. So we need to check that - * as well here. - * - * @param stdClass $questiondata - * @return bool - */ - public static function is_question_valid(stdClass $questiondata): bool { - return (self::is_qtype_installed($questiondata->qtype) && $questiondata->qtype !== 'missingtype'); - } - }