Skip to content

Commit dfa263d

Browse files
committed
feat: set white background on readonly editor content
Like qtype_essay does.
1 parent 194bda6 commit dfa263d

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

classes/local/attempt_ui/qpy_rich_text_editor.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use DOMNode;
2525
use DOMXPath;
2626
use file_exception;
27+
use html_writer;
2728
use Iterator;
2829
use moodle_exception;
2930
use moodle_url;
@@ -145,6 +146,7 @@ public static function from_element(DOMElement $element): ?static {
145146
* @throws stored_file_creation_exception
146147
*/
147148
public function render(question_attempt $qa, question_ui_renderer $renderer): DOMNode {
149+
$html = html_writer::start_div('qpy-editor-container ' . ($renderer->options->readonly ? 'readonly' : ''));
148150
if ($renderer->options->readonly) {
149151
global $PAGE;
150152
/** @var qtype_questionpy_renderer $qpyrenderer */
@@ -154,7 +156,7 @@ public function render(question_attempt $qa, question_ui_renderer $renderer): DO
154156
$editorsdata = utils::get_qpy_editors_data($responsestep->get_qt_data());
155157
$editordata = $editorsdata[$this->name] ?? null;
156158

157-
$html = $qpyrenderer->render_readonly_editor_content(
159+
$html .= $qpyrenderer->render_readonly_editor_content(
158160
$editordata,
159161
qubaid: $qa->get_usage_id(),
160162
slot: $qa->get_slot(),
@@ -164,24 +166,27 @@ public function render(question_attempt $qa, question_ui_renderer $renderer): DO
164166
rows: $this->rows,
165167
cols: $this->cols
166168
);
167-
return dom_utils::html_to_fragment($this->element->ownerDocument, $html);
168-
} {
169-
return $this->render_writable($renderer, $qa);
169+
} else {
170+
$html .= $this->render_writable($renderer, $qa);
170171
}
172+
173+
$html .= html_writer::end_div();
174+
175+
return dom_utils::html_to_fragment($this->element->ownerDocument, $html);
171176
}
172177

173178
/**
174179
* Renders an editor using the usual Moodle APIs.
175180
*
176181
* @param question_ui_renderer $renderer
177182
* @param question_attempt $qa
178-
* @return DOMDocumentFragment|false|void
183+
* @return string HTML
179184
* @throws coding_exception
180185
* @throws file_exception
181186
* @throws moodle_exception
182187
* @throws stored_file_creation_exception
183188
*/
184-
public function render_writable(question_ui_renderer $renderer, question_attempt $qa) {
189+
public function render_writable(question_ui_renderer $renderer, question_attempt $qa): string {
185190
$limits = $this->get_limits_in($renderer->options->context);
186191

187192
$alleditorsdata = utils::get_qpy_editors_data($qa);
@@ -241,7 +246,7 @@ public function render_writable(question_ui_renderer $renderer, question_attempt
241246

242247
$meditor->setValue($values);
243248

244-
return dom_utils::html_to_fragment($this->element->ownerDocument, $meditor->toHtml());
249+
return $meditor->toHtml();
245250
}
246251

247252
/**

styles.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ body.questionpy-iframe-body {
6060
}
6161
}
6262

63+
.qpy-editor-container.readonly {
64+
/* Adopted from .que.essay .qtype_essay_response.readonly. */
65+
background-color: var(--bs-white);
66+
}
67+
6368
/* Make question iframe seamless. */
6469
body.questionpy-iframe-body .formulation {
6570
padding: 0;

0 commit comments

Comments
 (0)