diff --git a/question/type/ddimageortext/question.php b/question/type/ddimageortext/question.php index f2839f7a389..94c2f861b55 100644 --- a/question/type/ddimageortext/question.php +++ b/question/type/ddimageortext/question.php @@ -119,9 +119,6 @@ class qtype_ddimageortext_drop_zone { /** @var array X and Y location of the drop zone */ public $xy; - /** @var string field name to use */ - public $fieldname; - /** * Create a drop zone object. * diff --git a/question/type/ddimageortext/rendererbase.php b/question/type/ddimageortext/rendererbase.php index 987b1f40623..1d140e4ecd0 100644 --- a/question/type/ddimageortext/rendererbase.php +++ b/question/type/ddimageortext/rendererbase.php @@ -103,18 +103,25 @@ class qtype_ddtoimage_renderer_base extends qtype_with_combined_feedback_rendere $output .= $dragimagehomes; $output .= html_writer::end_div(); + // Note, the mobile app implementation of ddimageortext relies on extracting the + // blob of places data out of the rendered HTML, which makes it impossible + // to clean up this structure of otherwise unnecessary stuff. + $placeinfoforjsandmobileapp = []; foreach ($question->places as $placeno => $place) { $varname = $question->field($placeno); - list($fieldname, $html) = $this->hidden_field_for_qt_var($qa, $varname, null, + [$fieldname, $html] = $this->hidden_field_for_qt_var($qa, $varname, null, ['placeinput', 'place' . $placeno, 'group' . $place->group]); $output .= $html; + $placeinfo = (object) $place; + $placeinfo->fieldname = $fieldname; + $placeinfoforjsandmobileapp[$placeno] = $placeinfo; } $output .= html_writer::end_div(); $this->page->requires->string_for_js('blank', 'qtype_ddimageortext'); $this->page->requires->js_call_amd('qtype_ddimageortext/question', 'init', - [$qa->get_outer_question_div_unique_id(), $options->readonly, $question->places]); + [$qa->get_outer_question_div_unique_id(), $options->readonly, $placeinfoforjsandmobileapp]); if ($qa->get_state() == question_state::$invalid) { $output .= html_writer::div($question->get_validation_error($qa->get_last_qt_data()), 'validationerror');