MDL-6826 New button added!

This commit is contained in:
nicolasconnault 2008-01-23 12:56:13 +00:00
parent cde5e2be6d
commit 6b4671097b
3 changed files with 40 additions and 1 deletions

View File

@ -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 {

View File

@ -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');
}
}
?>

View File

@ -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';