MDL-82953 badges: Fix redirect when form is cancelled

From the new badge page, when the form is cancelled, a redirect should
be done to the badges/index.php.
This is a regression introduced when newbadge.php and edit.php pages
were merged.
This commit is contained in:
Sara Arjona
2024-08-30 11:37:02 +02:00
parent 072fb90384
commit 3c47fbe3b6
2 changed files with 44 additions and 3 deletions
+5 -1
View File
@@ -60,6 +60,8 @@ if (!empty($badgeid)) {
} else {
require_capability('moodle/badges:configuredetails', $context);
}
$cancelurl = new moodle_url('/badges/overview.php', ['id' => $badgeid]);
} else {
// New badge.
if ($courseid) {
@@ -79,6 +81,8 @@ if (!empty($badgeid)) {
// Check capabilities.
require_capability('moodle/badges:createbadge', $context);
$cancelurl = new moodle_url('/badges/index.php', ['type' => $badge->type, 'id' => $courseid]);
}
// Check if course badges are enabled.
@@ -141,7 +145,7 @@ if ($badge->id) {
$form = new $formclass($currenturl, $params);
if ($form->is_cancelled()) {
redirect(new moodle_url('/badges/overview.php', ['id' => $badgeid]));
redirect($cancelurl);
} else if ($form->is_submitted() && $form->is_validated() && ($data = $form->get_data())) {
switch ($action) {
case 'new':
+39 -2
View File
@@ -67,7 +67,6 @@ Feature: Add badges to the system
| Image caption | Test caption image |
And I upload "badges/tests/behat/badge.png" file to "Image" filemanager
And I press "Create badge"
And I wait until the page is ready
And I navigate to "Badges > Manage badges" in site administration
And I press "Add a new badge"
And I set the following fields to these values:
@@ -83,7 +82,6 @@ Feature: Add badges to the system
And I should see "This badge does not have any related badges."
And I press "Add related badge"
And I follow "Related badges"
And I wait until the page is ready
And I follow "Related badges"
And I set the field "relatedbadgeids[]" to "Test Badge 1 (version: v1, language: French, Site badges)"
When I press "Save changes"
@@ -220,3 +218,42 @@ Feature: Add badges to the system
| badges_defaultissuername | Test Badge Site |
And I navigate to "Badges > Add a new badge" in site administration
And the field "Issuer name" matches value "Test Badge Site"
Scenario: Cancel button behaviour when creating badges
Given the following "course" exists:
| fullname | Course 1 |
| shortname | C1 |
And the following "core_badges > Badge" exists:
| name | Site Badge 1 |
| description | Site badge 1 description |
| image | badges/tests/behat/badge.png |
| status | 0 |
| type | 1 |
And the following "core_badges > Badge" exists:
| name | Course Badge 1 |
| course | C1 |
| description | Course badge 1 description |
| image | badges/tests/behat/badge.png |
| status | 0 |
| type | 2 |
# Site badge: cancel when creating.
When I navigate to "Badges > Add a new badge" in site administration
And I click on "Cancel" "button"
Then I should see "Manage badges"
And I should see "Add a new badge"
# Site badge: cancel when editing.
And I press "Edit" action in the "Site Badge 1" report row
And I click on "Cancel" "button"
And I should see "Site badge 1"
And I should not see "Save changes"
# Course badge: cancel when creating.
And I am on the "Course 1" "course" page
And I navigate to "Badges > Manage badges > Add a new badge" in current page administration
And I click on "Cancel" "button"
Then I should see "Manage badges"
And I should see "Add a new badge"
# Course badge: cancel when editing.
And I press "Edit" action in the "Course Badge 1" report row
And I click on "Cancel" "button"
And I should see "Course badge 1"
And I should not see "Save changes"