mirror of
https://github.com/moodle/moodle.git
synced 2025-04-19 07:25:30 +02:00
MDL-76849 qtype_essay: Allow question number inclusion in answer fields
* Have the following classes extend qtype_essay_format_renderer_base as they have been meant to: - qtype_essay_format_editor_renderer - qtype_essay_format_noinline_renderer - qtype_essay_format_plain_renderer * Add a question_display_options instance variable for qtype_essay_format_renderer_base so its subclasses can use it to generate the label for their respective answer fields.
This commit is contained in:
parent
787278601c
commit
d5cf25faf5
@ -38,7 +38,10 @@ class qtype_essay_renderer extends qtype_renderer {
|
||||
question_display_options $options) {
|
||||
global $CFG;
|
||||
$question = $qa->get_question();
|
||||
|
||||
/** @var qtype_essay_format_renderer_base $responseoutput */
|
||||
$responseoutput = $question->get_format_renderer($this->page);
|
||||
$responseoutput->set_displayoptions($options);
|
||||
|
||||
// Answer field.
|
||||
$step = $qa->get_last_step_with_qt_var('answer');
|
||||
@ -131,7 +134,8 @@ class qtype_essay_renderer extends qtype_renderer {
|
||||
|
||||
$labelbyid = $qa->get_qt_field_name('attachments') . '_label';
|
||||
|
||||
$output = html_writer::tag('h4', get_string('answerfiles', 'qtype_essay'), ['id' => $labelbyid, 'class' => 'sr-only']);
|
||||
$fileslabel = $options->add_question_identifier_to_label(get_string('answerfiles', 'qtype_essay'));
|
||||
$output = html_writer::tag('h4', $fileslabel, ['id' => $labelbyid, 'class' => 'sr-only']);
|
||||
$output .= html_writer::tag('ul', implode($filelist), [
|
||||
'aria-labelledby' => $labelbyid,
|
||||
'class' => 'list-unstyled m-0',
|
||||
@ -182,7 +186,8 @@ class qtype_essay_renderer extends qtype_renderer {
|
||||
}
|
||||
|
||||
$output = html_writer::start_tag('fieldset');
|
||||
$output .= html_writer::tag('legend', get_string('answerfiles', 'qtype_essay'), ['class' => 'sr-only']);
|
||||
$fileslabel = $options->add_question_identifier_to_label(get_string('answerfiles', 'qtype_essay'));
|
||||
$output .= html_writer::tag('legend', $fileslabel, ['class' => 'sr-only']);
|
||||
$output .= $filesrenderer->render($fm);
|
||||
$output .= html_writer::empty_tag('input', [
|
||||
'type' => 'hidden',
|
||||
@ -216,6 +221,19 @@ class qtype_essay_renderer extends qtype_renderer {
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
abstract class qtype_essay_format_renderer_base extends plugin_renderer_base {
|
||||
|
||||
/** @var question_display_options Question display options instance for any necessary information for rendering the question. */
|
||||
protected $displayoptions;
|
||||
|
||||
/**
|
||||
* Question number setter.
|
||||
*
|
||||
* @param question_display_options $displayoptions
|
||||
*/
|
||||
public function set_displayoptions(question_display_options $displayoptions): void {
|
||||
$this->displayoptions = $displayoptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the students respone when the question is in read-only mode.
|
||||
* @param string $name the variable name this input edits.
|
||||
@ -253,7 +271,7 @@ abstract class qtype_essay_format_renderer_base extends plugin_renderer_base {
|
||||
* @copyright 2013 Binghamton University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class qtype_essay_format_noinline_renderer extends plugin_renderer_base {
|
||||
class qtype_essay_format_noinline_renderer extends qtype_essay_format_renderer_base {
|
||||
|
||||
protected function class_name() {
|
||||
return 'qtype_essay_noinline';
|
||||
@ -276,7 +294,7 @@ class qtype_essay_format_noinline_renderer extends plugin_renderer_base {
|
||||
* @copyright 2011 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class qtype_essay_format_editor_renderer extends plugin_renderer_base {
|
||||
class qtype_essay_format_editor_renderer extends qtype_essay_format_renderer_base {
|
||||
protected function class_name() {
|
||||
return 'qtype_essay_editor';
|
||||
}
|
||||
@ -284,7 +302,8 @@ class qtype_essay_format_editor_renderer extends plugin_renderer_base {
|
||||
public function response_area_read_only($name, $qa, $step, $lines, $context) {
|
||||
$labelbyid = $qa->get_qt_field_name($name) . '_label';
|
||||
|
||||
$output = html_writer::tag('h4', get_string('answertext', 'qtype_essay'), ['id' => $labelbyid, 'class' => 'sr-only']);
|
||||
$responselabel = $this->displayoptions->add_question_identifier_to_label(get_string('answertext', 'qtype_essay'));
|
||||
$output = html_writer::tag('h4', $responselabel, ['id' => $labelbyid, 'class' => 'sr-only']);
|
||||
$output .= html_writer::tag('div', $this->prepare_response($name, $qa, $step, $context), [
|
||||
'role' => 'textbox',
|
||||
'aria-readonly' => 'true',
|
||||
@ -320,7 +339,8 @@ class qtype_essay_format_editor_renderer extends plugin_renderer_base {
|
||||
$editor->use_editor($id, $this->get_editor_options($context),
|
||||
$this->get_filepicker_options($context, $draftitemid));
|
||||
|
||||
$output = html_writer::tag('label', get_string('answertext', 'qtype_essay'), [
|
||||
$responselabel = $this->displayoptions->add_question_identifier_to_label(get_string('answertext', 'qtype_essay'));
|
||||
$output = html_writer::tag('label', $responselabel, [
|
||||
'class' => 'sr-only',
|
||||
'for' => $id,
|
||||
]);
|
||||
@ -514,7 +534,7 @@ class qtype_essay_format_editorfilepicker_renderer extends qtype_essay_format_ed
|
||||
* @copyright 2011 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class qtype_essay_format_plain_renderer extends plugin_renderer_base {
|
||||
class qtype_essay_format_plain_renderer extends qtype_essay_format_renderer_base {
|
||||
/**
|
||||
* @return string the HTML for the textarea.
|
||||
*/
|
||||
@ -532,7 +552,8 @@ class qtype_essay_format_plain_renderer extends plugin_renderer_base {
|
||||
public function response_area_read_only($name, $qa, $step, $lines, $context) {
|
||||
$id = $qa->get_qt_field_name($name) . '_id';
|
||||
|
||||
$output = html_writer::tag('label', get_string('answertext', 'qtype_essay'), ['class' => 'sr-only', 'for' => $id]);
|
||||
$responselabel = $this->displayoptions->add_question_identifier_to_label(get_string('answertext', 'qtype_essay'));
|
||||
$output = html_writer::tag('label', $responselabel, ['class' => 'sr-only', 'for' => $id]);
|
||||
$output .= $this->textarea($step->get_qt_var($name), $lines, ['id' => $id, 'readonly' => 'readonly']);
|
||||
return $output;
|
||||
}
|
||||
@ -541,7 +562,8 @@ class qtype_essay_format_plain_renderer extends plugin_renderer_base {
|
||||
$inputname = $qa->get_qt_field_name($name);
|
||||
$id = $inputname . '_id';
|
||||
|
||||
$output = html_writer::tag('label', get_string('answertext', 'qtype_essay'), ['class' => 'sr-only', 'for' => $id]);
|
||||
$responselabel = $this->displayoptions->add_question_identifier_to_label(get_string('answertext', 'qtype_essay'));
|
||||
$output = html_writer::tag('label', $responselabel, ['class' => 'sr-only', 'for' => $id]);
|
||||
$output .= $this->textarea($step->get_qt_var($name), $lines, ['name' => $inputname, 'id' => $id]);
|
||||
$output .= html_writer::empty_tag('input', ['type' => 'hidden', 'name' => $inputname . 'format', 'value' => FORMAT_PLAIN]);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user