From 6b4671097b7a6ca0ee7fa4d251c54ee44817dc37 Mon Sep 17 00:00:00 2001 From: nicolasconnault Date: Wed, 23 Jan 2008 12:56:13 +0000 Subject: [PATCH] MDL-6826 New button added! --- course/modedit.php | 6 ++++++ course/moodleform_mod.php | 33 ++++++++++++++++++++++++++++++++- lang/en_utf8/moodle.php | 2 ++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/course/modedit.php b/course/modedit.php index bee718346f..6336753a0e 100644 --- a/course/modedit.php +++ b/course/modedit.php @@ -12,6 +12,8 @@ $update = optional_param('update', 0, PARAM_INT); $return = optional_param('return', 0, PARAM_BOOL); //return to course/view.php if false or mod/modname/view.php if true $type = optional_param('type', '', PARAM_ALPHANUM); + $submitbutton = optional_param('submitbutton', null, PARAM_ALPHANUM); + $submitbutton2 = optional_param('submitbutton2', null, PARAM_ALPHANUM); if (!empty($add)) { $section = required_param('section', PARAM_INT); @@ -408,7 +410,11 @@ rebuild_course_cache($course->id); + if ($submitbutton) { redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule"); + } elseif ($submitbutton2) { + redirect("$CFG->wwwroot/course/view.php?id=$course->id"); + } exit; } else { diff --git a/course/moodleform_mod.php b/course/moodleform_mod.php index 82a66b3ac4..9553bc0179 100644 --- a/course/moodleform_mod.php +++ b/course/moodleform_mod.php @@ -2,7 +2,7 @@ require_once ($CFG->libdir.'/formslib.php'); /** * This class adds extra methods to form wrapper specific to be used for module - * add / update forms (mod/{modname}.mod_form.php replaces deprecared mod/{modname}/mod.html + * add / update forms (mod/{modname}.mod_form.php replaces deprecated mod/{modname}/mod.html * */ class moodleform_mod extends moodleform { @@ -294,6 +294,37 @@ class moodleform_mod extends moodleform { $mform->setType('return', PARAM_BOOL); } + /** + * Overriding formslib's add_action_buttons() method, to add an extra submit "save changes and return" button. + * + * @param bool $cancel + * @param string $submitlabel + * @param string $submit2label + * @return void + */ + function add_action_buttons($cancel=true, $submitlabel=null, $submit2label=null) { + if (is_null($submitlabel)) { + $submitlabel = get_string('savechangesanddisplay'); + } + + if (is_null($submit2label)) { + $submit2label = get_string('savechangesandreturntocourse'); + } + + $mform =& $this->_form; + + //when two elements we need a group + $buttonarray=array(); + $buttonarray[] = &$mform->createElement('submit', 'submitbutton', $submitlabel); + $buttonarray[] = &$mform->createElement('submit', 'submitbutton2', $submit2label); + + if ($cancel) { + $buttonarray[] = &$mform->createElement('cancel'); + } + + $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false); + $mform->closeHeaderBefore('buttonar'); + } } ?> diff --git a/lang/en_utf8/moodle.php b/lang/en_utf8/moodle.php index c193a6183c..a71cb0bd13 100644 --- a/lang/en_utf8/moodle.php +++ b/lang/en_utf8/moodle.php @@ -1258,6 +1258,8 @@ $string['rsserror'] = 'Error reading RSS data'; $string['rsstype'] = 'RSS feed for this activity'; $string['saveandnext'] = 'Save and show next'; $string['savechanges'] = 'Save changes'; +$string['savechangesanddisplay'] = 'Save changes and display'; +$string['savechangesandreturntocourse'] = 'Save changes and return to course'; $string['savedat'] = 'Saved at:'; $string['savepreferences'] = 'Save preferences'; $string['saveto'] = 'Save to'; -- 2.39.5