Skip to content

Commit

Permalink
MDL-6826 New button added!
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasconnault committed Jan 23, 2008
1 parent 7bff26b commit b55b207
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
18 changes: 12 additions & 6 deletions course/modedit.php
Expand Up @@ -8,10 +8,12 @@

require_login();

$add = optional_param('add', 0, PARAM_ALPHA);
$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);
$add = optional_param('add', 0, PARAM_ALPHA);
$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);
Expand Down Expand Up @@ -407,8 +409,12 @@
}

rebuild_course_cache($course->id);

redirect("$CFG->wwwroot/mod/$module->name/view.php?id=$fromform->coursemodule");

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 {
Expand Down
33 changes: 32 additions & 1 deletion course/moodleform_mod.php
Expand Up @@ -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 {
Expand Down Expand Up @@ -293,7 +293,38 @@ function standard_hidden_coursemodule_elements(){
$mform->addElement('hidden', 'return', 0);
$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');
}
}

?>
2 changes: 2 additions & 0 deletions lang/en_utf8/moodle.php
Expand Up @@ -1256,6 +1256,8 @@
$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';
Expand Down

0 comments on commit b55b207

Please sign in to comment.