Skip to content

Commit

Permalink
MDL-61402 Core: Add a cancel button to edit profile page
Browse files Browse the repository at this point in the history
  • Loading branch information
mkassaei committed Feb 16, 2018
1 parent d1b4ca9 commit 7ce538b
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 22 deletions.
22 changes: 12 additions & 10 deletions user/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,20 @@

$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 = '';

Expand Down
2 changes: 1 addition & 1 deletion user/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function definition () {
// 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);
}
Expand Down
25 changes: 15 additions & 10 deletions user/editadvanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,21 @@
'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)) {
Expand Down Expand Up @@ -292,15 +306,6 @@
// 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 {
Expand Down
2 changes: 1 addition & 1 deletion user/editadvanced_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function definition() {
$btnstring = get_string('updatemyprofile');
}

$this->add_action_buttons(false, $btnstring);
$this->add_action_buttons(true, $btnstring);

$this->set_data($user);
}
Expand Down
14 changes: 14 additions & 0 deletions user/tests/behat/name_fields.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

0 comments on commit 7ce538b

Please sign in to comment.