Skip to content

Commit 92b0806

Browse files
committed
feat: make initial qpy:rich-text-editor size configurable
1 parent 44514c4 commit 92b0806

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

classes/local/attempt_ui/qpy_rich_text_editor.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,20 @@
4545
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
4646
*/
4747
class qpy_rich_text_editor implements custom_xhtml_element {
48-
// The default in MoodleQuickForm_editor.
48+
// Same as MoodleQuickForm_editor.
4949
/** @var int */
50-
private const RETURN_TYPES = FILE_INTERNAL | FILE_EXTERNAL | FILE_REFERENCE | FILE_CONTROLLED_LINK;
50+
private const DEFAULT_ROWS = 15;
51+
/** @var int */
52+
private const DEFAULT_COLS = 80;
5153

5254
/**
5355
* Trivial private constructor. Use {@see from_element()}.
5456
* @param DOMElement $element
5557
* @param string $name
5658
* @param bool $required
5759
* @param string|null $default
60+
* @param int $rows
61+
* @param int $cols
5862
*/
5963
private function __construct(
6064
/** @var DOMElement */
@@ -65,6 +69,10 @@ private function __construct(
6569
public readonly bool $required,
6670
/** @var string */
6771
public readonly ?string $default,
72+
/** @var int */
73+
public readonly int $rows,
74+
/** @var int */
75+
public readonly int $cols,
6876
) {
6977
}
7078

@@ -110,11 +118,14 @@ public static function from_element(DOMElement $element): ?static {
110118
return null;
111119
}
112120

113-
$required = $element->hasAttribute('required');
114-
115-
$default = $element->hasAttribute('default') ? $element->getAttribute('default') : null;
116-
117-
return new static($element, $name, $required, $default);
121+
return new static(
122+
$element,
123+
$name,
124+
required: $element->hasAttribute('required'),
125+
default: $element->hasAttribute('default') ? $element->getAttribute('default') : null,
126+
rows: $element->getAttribute('initial-rows') ?: self::DEFAULT_ROWS,
127+
cols: $element->getAttribute('initial-cols') ?: self::DEFAULT_COLS
128+
);
118129
}
119130

120131
/**
@@ -179,6 +190,10 @@ public function render(question_attempt $qa, question_ui_renderer $renderer): DO
179190
$meditor = new MoodleQuickForm_editor(
180191
elementName: $this->name,
181192
elementLabel: null,
193+
attributes: [
194+
'rows' => $this->rows,
195+
'cols' => $this->cols,
196+
],
182197
options: $options
183198
);
184199
$meditor->_generateId();

0 commit comments

Comments
 (0)