From d438027a185ff1b5c6e6c5c45bba4f5c36c07e19 Mon Sep 17 00:00:00 2001 From: Mikhail Golenkov Date: Wed, 5 Feb 2020 12:51:43 +1100 Subject: [PATCH] Reorganize warning and buttons for Edit form #172. --- classes/form/outage/edit.php | 19 +++++++------------ edit.php | 14 +++++--------- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/classes/form/outage/edit.php b/classes/form/outage/edit.php index 7fb7d93..b37df11 100644 --- a/classes/form/outage/edit.php +++ b/classes/form/outage/edit.php @@ -82,6 +82,9 @@ class edit extends moodleform { $mform->addHelpButton('description', 'description', 'auth_outage'); $mform->addElement('static', 'usagehints', '', get_string('textplaceholdershint', 'auth_outage')); + $mform->addElement('static', 'warningreenablemaintenancemode', ''); + + $this->add_action_buttons(); } /** @@ -145,6 +148,7 @@ class edit extends moodleform { */ public function set_data($outage) { global $OUTPUT; + $mform = $this->_form; // Cannot change method signature, check type. if ($outage instanceof outage) { @@ -158,21 +162,12 @@ class edit extends moodleform { 'description' => ['text' => $outage->description, 'format' => '1'], ]); - if (!empty($outage->id) && $outage->autostart && $outage->starttime < time() && - $outage->stoptime > time()) { - $this->_form->addElement('html', - $OUTPUT->notification(get_string('warningreenablemaintenancemode', 'auth_outage'), 'notifywarning')); + if (!empty($outage->id) && $outage->autostart && $outage->starttime < time() && $outage->stoptime > time()) { + $warning = $mform->getElement('warningreenablemaintenancemode'); + $warning->setValue($OUTPUT->notification(get_string('warningreenablemaintenancemode', 'auth_outage'), 'notifywarning')); } } else { throw new coding_exception('$outage must be an outage object.', $outage); } } - - /** - * {@inheritDoc} - * @see moodleform::definition_after_data() - */ - public function definition_after_data() { - $this->add_action_buttons(); - } } diff --git a/edit.php b/edit.php index 0d7cb24..5cd25f8 100644 --- a/edit.php +++ b/edit.php @@ -38,15 +38,11 @@ $PAGE->set_url(new moodle_url('/auth/outage/manage.php')); $mform = new edit(); -if ($mform->is_submitted()) { - $mform->is_validated(); - - if ($mform->is_cancelled()) { - redirect(new moodle_url('/auth/outage/manage.php')); - } else if ($outage = $mform->get_data()) { - $id = outagedb::save($outage); - redirect(new moodle_url('/auth/outage/manage.php')); - } +if ($mform->is_cancelled()) { + redirect(new moodle_url('/auth/outage/manage.php')); +} else if ($outage = $mform->get_data()) { + $id = outagedb::save($outage); + redirect(new moodle_url('/auth/outage/manage.php')); } $clone = optional_param('clone', 0, PARAM_INT);