diff --git a/mod/label/lang/en/label.php b/mod/label/lang/en/label.php index 0a50c887442..5856a0b9363 100644 --- a/mod/label/lang/en/label.php +++ b/mod/label/lang/en/label.php @@ -43,6 +43,8 @@ $string['indicator:socialbreadthdef_help'] = 'The participant has reached this p $string['indicator:socialbreadthdef_link'] = 'Learning_analytics_indicators#Social_breadth'; $string['label:addinstance'] = 'Add a new Text and media area'; $string['label:view'] = 'View Text and media area'; +$string['labelname'] = 'Name'; +$string['labelname_help'] = 'Will be shown in course index, activity completion, etc. If left empty, will automatically be generated from the first characters of the text.'; $string['labeltext'] = 'Text'; $string['modulename'] = 'Text and media area'; $string['modulename_help'] = 'The Text and media area enables you to display text and multimedia on the course page. diff --git a/mod/label/lib.php b/mod/label/lib.php index a9258f8d459..aff5cbceaa0 100644 --- a/mod/label/lib.php +++ b/mod/label/lib.php @@ -34,6 +34,11 @@ define("LABEL_MAX_NAME_LENGTH", 50); * @return string */ function get_label_name($label) { + // Return label name if not empty. + if ($label->name) { + return $label->name; + } + $context = context_module::instance($label->coursemodule); $intro = format_text($label->intro, $label->introformat, ['filter' => false, 'context' => $context]); $name = html_to_text(format_string($intro, true, ['context' => $context])); diff --git a/mod/label/mod_form.php b/mod/label/mod_form.php index fec23dfcd57..e84417e6133 100644 --- a/mod/label/mod_form.php +++ b/mod/label/mod_form.php @@ -37,6 +37,16 @@ class mod_label_mod_form extends moodleform_mod { $mform = $this->_form; $mform->addElement('header', 'generalhdr', get_string('general')); + + // Add element for name. + $mform->addElement('text', 'name', get_string('labelname', 'label'), array('size' => '64')); + if (!empty($CFG->formatstringstriptags)) { + $mform->setType('name', PARAM_TEXT); + } else { + $mform->setType('name', PARAM_CLEANHTML); + } + $mform->addHelpButton('name', 'labelname', 'label'); + $this->standard_intro_elements(get_string('labeltext', 'label')); // Label does not add "Show description" checkbox meaning that 'intro' is always shown on the course page. @@ -51,4 +61,22 @@ class mod_label_mod_form extends moodleform_mod { } + /** + * Override validation in order to make name field non-required. + * + * @param array $data + * @param array $files + * @return array + */ + public function validation($data, $files) { + $errors = parent::validation($data, $files); + // Name field should not be required. + if (array_key_exists('name', $errors)) { + if ($errors['name'] === get_string('required')) { + unset($errors['name']); + } + } + return $errors; + } + } diff --git a/mod/label/version.php b/mod/label/version.php index 2e373641a0f..ea3539a53c5 100644 --- a/mod/label/version.php +++ b/mod/label/version.php @@ -24,7 +24,7 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2023042400; // The current module version (Date: YYYYMMDDXX). +$plugin->version = 2023042401; // The current module version (Date: YYYYMMDDXX). $plugin->requires = 2023041800; // Requires this Moodle version. $plugin->component = 'mod_label'; // Full name of the plugin (used for diagnostics) $plugin->cron = 0;