MDL-73188 tool_usertours: Fix validation of text content

This commit is contained in:
Jun Pataleta 2022-01-28 20:48:49 +08:00
parent 67b2e10f03
commit e1f34b394d

View File

@ -159,9 +159,19 @@ class editstep extends \moodleform {
}
}
// Validate manually entered text content. Validation logic derived from \MoodleQuickForm_Rule_Required::validate()
// without the checking of the "strictformsrequired" admin setting.
if ($data['contenttype'] == static::CONTENTTYPE_MANUAL) {
if (strip_tags($data['content']['text']) == '') {
$errors['content'] = get_string('required');
$value = $data['content']['text'] ?? '';
// All tags except img, canvas and hr, plus all forms of whitespaces.
$stripvalues = [
'#</?(?!img|canvas|hr).*?>#im',
'#(\xc2\xa0|\s|&nbsp;)#',
];
$value = preg_replace($stripvalues, '', (string)$value);
if (empty($value)) {
$errors['contenthtmlgrp'] = get_string('required');
}
}
@ -203,7 +213,7 @@ class editstep extends \moodleform {
if ($data->contenttype == static::CONTENTTYPE_LANGSTRING) {
$data->content = [
'text' => $data->contentlangstring,
'format' => 1,
'format' => FORMAT_HTML,
];
}
}