Skip to content

Commit

Permalink
Merge branch 'MDL-53071-master' of git://github.com/junpataleta/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Feb 24, 2016
2 parents e8d9087 + eb66223 commit 316d657
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions course/editsection_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ function definition() {
$mform->addGroup($elementgroup, 'name_group', get_string('sectionname'), ' ', false);
$mform->addGroupRule('name_group', array('name' => array(array(get_string('maximumchars', '', 255), 'maxlength', 255))));

// Add rule for name_group to make sure that the section name is not blank if 'Use default section name'
// checkbox is unchecked.
$mform->addRule('name_group', get_string('required'), 'required', null, 'client');

$mform->setDefault('usedefaultname', true);
$mform->setType('name', PARAM_TEXT);
$mform->disabledIf('name','usedefaultname','checked');
Expand Down Expand Up @@ -102,7 +98,7 @@ function set_data($default_values) {
$editoroptions = $this->_customdata['editoroptions'];
$default_values = file_prepare_standard_editor($default_values, 'summary', $editoroptions,
$editoroptions['context'], 'course', 'section', $default_values->id);
$default_values->usedefaultname = (is_null($default_values->name));
$default_values->usedefaultname = (strval($default_values->name) === '');
parent::set_data($default_values);
}

Expand All @@ -116,8 +112,9 @@ function get_data() {
$data = parent::get_data();
if ($data !== null) {
$editoroptions = $this->_customdata['editoroptions'];
// Set name as an empty string if use default section name is checked.
if (!empty($data->usedefaultname)) {
$data->name = null;
$data->name = '';
}
$data = file_postupdate_standard_editor($data, 'summary', $editoroptions,
$editoroptions['context'], 'course', 'section', $data->id);
Expand All @@ -141,15 +138,6 @@ public function validation($data, $files) {
\core_availability\frontend::report_validation_errors($data, $errors);
}

// Validate section name if 'Use default section name' is unchecked.
if (empty($data['usedefaultname'])) {
// Make sure the trimmed value of section name is not empty.
$trimmedname = trim($data['name']);
if (empty($trimmedname)) {
$errors['name_group'] = get_string('required');
}
}

return $errors;
}
}

0 comments on commit 316d657

Please sign in to comment.