MDL-77673 ddimageortext: keep JS data just for the mobile app

This commit is contained in:
Tim Hunt 2023-03-17 16:08:23 +00:00 committed by Juan Leyva
parent f3bf17cdfb
commit 8489808536
2 changed files with 9 additions and 5 deletions

View File

@ -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.
*

View File

@ -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');