From 7ce538be0f76cf411d99c7131346402e9c8f96bd Mon Sep 17 00:00:00 2001 From: M Kassaei Date: Thu, 8 Feb 2018 11:14:37 +0000 Subject: [PATCH] MDL-61402 Core: Add a cancel button to edit profile page --- user/edit.php | 22 ++++++++++++---------- user/edit_form.php | 2 +- user/editadvanced.php | 25 +++++++++++++++---------- user/editadvanced_form.php | 2 +- user/tests/behat/name_fields.feature | 14 ++++++++++++++ 5 files changed, 43 insertions(+), 22 deletions(-) diff --git a/user/edit.php b/user/edit.php index f837016ed7e..7fc19ffb94e 100644 --- a/user/edit.php +++ b/user/edit.php @@ -176,18 +176,20 @@ $userform = new user_edit_form(new moodle_url($PAGE->url, array('returnto' => $r $emailchanged = false; -if ($usernew = $userform->get_data()) { - - // Deciding where to send the user back in most cases. - if ($returnto === 'profile') { - if ($course->id != SITEID) { - $returnurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id)); - } else { - $returnurl = new moodle_url('/user/profile.php', array('id' => $user->id)); - } +// Deciding where to send the user back in most cases. +if ($returnto === 'profile') { + if ($course->id != SITEID) { + $returnurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id)); } else { - $returnurl = new moodle_url('/user/preferences.php', array('userid' => $user->id)); + $returnurl = new moodle_url('/user/profile.php', array('id' => $user->id)); } +} else { + $returnurl = new moodle_url('/user/preferences.php', array('userid' => $user->id)); +} + +if ($userform->is_cancelled()) { + redirect($returnurl); +} else if ($usernew = $userform->get_data()) { $emailchangedhtml = ''; diff --git a/user/edit_form.php b/user/edit_form.php index bb614acaf2b..4f2214f4c44 100644 --- a/user/edit_form.php +++ b/user/edit_form.php @@ -104,7 +104,7 @@ class user_edit_form extends moodleform { // Next the customisable profile fields. profile_definition($mform, $userid); - $this->add_action_buttons(false, get_string('updatemyprofile')); + $this->add_action_buttons(true, get_string('updatemyprofile')); $this->set_data($user); } diff --git a/user/editadvanced.php b/user/editadvanced.php index 6f3d07e40cc..07fc5e06315 100644 --- a/user/editadvanced.php +++ b/user/editadvanced.php @@ -154,7 +154,21 @@ $userform = new user_editadvanced_form(new moodle_url($PAGE->url, array('returnt 'filemanageroptions' => $filemanageroptions, 'user' => $user)); -if ($usernew = $userform->get_data()) { + +// Deciding where to send the user back in most cases. +if ($returnto === 'profile') { + if ($course->id != SITEID) { + $returnurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id)); + } else { + $returnurl = new moodle_url('/user/profile.php', array('id' => $user->id)); + } +} else { + $returnurl = new moodle_url('/user/preferences.php', array('userid' => $user->id)); +} + +if ($userform->is_cancelled()) { + redirect($returnurl); +} else if ($usernew = $userform->get_data()) { $usercreated = false; if (empty($usernew->auth)) { @@ -292,15 +306,6 @@ if ($usernew = $userform->get_data()) { // Somebody double clicked when editing admin user during install. redirect("$CFG->wwwroot/$CFG->admin/"); } else { - if ($returnto === 'profile') { - if ($course->id != SITEID) { - $returnurl = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id)); - } else { - $returnurl = new moodle_url('/user/profile.php', array('id' => $user->id)); - } - } else { - $returnurl = new moodle_url('/user/preferences.php', array('userid' => $user->id)); - } redirect($returnurl); } } else { diff --git a/user/editadvanced_form.php b/user/editadvanced_form.php index d2bd16a96cf..fe2fd312bce 100644 --- a/user/editadvanced_form.php +++ b/user/editadvanced_form.php @@ -154,7 +154,7 @@ class user_editadvanced_form extends moodleform { $btnstring = get_string('updatemyprofile'); } - $this->add_action_buttons(false, $btnstring); + $this->add_action_buttons(true, $btnstring); $this->set_data($user); } diff --git a/user/tests/behat/name_fields.feature b/user/tests/behat/name_fields.feature index d309ffd7bc4..4f26b277ae6 100644 --- a/user/tests/behat/name_fields.feature +++ b/user/tests/behat/name_fields.feature @@ -35,6 +35,13 @@ Feature: Both first name and surname are always available for every user # End UI test covering "I open my profile in edit mode" When I set the field "First name" to " " And I set the field "Surname" to " " + And I click on "Cancel" "button" + And I follow "Profile" in the user menu + And I click on "Edit profile" "link" in the "region-main" "region" + Then I should see "Foo" + And I should see "Bar" + When I set the field "First name" to " " + And I set the field "Surname" to " " And I click on "Update profile" "button" Then I should see "Missing given name" And I should see "Missing surname" @@ -49,6 +56,13 @@ Feature: Both first name and surname are always available for every user And I click on "Edit profile" "link" in the "region-main" "region" When I set the field "First name" to " " And I set the field "Surname" to " " + And I click on "Cancel" "button" + And I follow "Foo Bar" + And I click on "Edit profile" "link" in the "region-main" "region" + Then I should see "Foo" + And I should see "Bar" + When I set the field "First name" to " " + And I set the field "Surname" to " " And I click on "Update profile" "button" Then I should see "Missing given name" And I should see "Missing surname"