diff --git a/grade/classes/form/add_category.php b/grade/classes/form/add_category.php
index bbbe49d1f90..dc754d9e945 100644
--- a/grade/classes/form/add_category.php
+++ b/grade/classes/form/add_category.php
@@ -60,10 +60,7 @@ class add_category extends dynamic_form {
$courseid = $this->optional_param('courseid', null, PARAM_INT);
$id = $this->optional_param('category', null, PARAM_INT);
- if (!isset($id) || $id !== -1) {
- if (!$gradecategory = grade_category::fetch(['id' => $id, 'courseid' => $courseid])) {
- throw new \moodle_exception('invalidcategory');
- }
+ if ($gradecategory = grade_category::fetch(['id' => $id, 'courseid' => $courseid])) {
$gradecategory->apply_forced_settings();
$category = $gradecategory->get_record_data();
// Set parent.
@@ -257,8 +254,8 @@ class add_category extends dynamic_form {
}
$url = new moodle_url('/grade/edit/tree/category.php', $params);
$url = $this->gpr->add_url_params($url);
- $url = '' . get_string('showmore', 'form') .'';
- $mform->addElement('static', 'test', $url);
+ $url = '' . get_string('showmore', 'form') .'';
+ $mform->addElement('static', 'advancedform', $url);
// Add return tracking info.
$this->gpr->add_mform_elements($mform);
diff --git a/grade/classes/form/add_outcome.php b/grade/classes/form/add_outcome.php
index 5a6ecc967e5..bb1cb87a1db 100644
--- a/grade/classes/form/add_outcome.php
+++ b/grade/classes/form/add_outcome.php
@@ -287,7 +287,7 @@ class add_outcome extends dynamic_form {
$url = new moodle_url('/grade/edit/tree/outcomeitem.php', ['id' => $id, 'courseid' => $courseid]);
$url = $this->gpr->add_url_params($url);
- $url = '' . get_string('showmore', 'form') .'';
+ $url = '' . get_string('showmore', 'form') .'';
$mform->addElement('static', 'advancedform', $url);
// Add return tracking info.
diff --git a/grade/edit/tree/category.php b/grade/edit/tree/category.php
index 3daddf7c1de..c7bc01b56d8 100644
--- a/grade/edit/tree/category.php
+++ b/grade/edit/tree/category.php
@@ -22,6 +22,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+use core_grades\form\add_category;
+
require_once('../../../config.php');
require_once($CFG->dirroot.'/grade/lib.php');
require_once($CFG->dirroot.'/grade/edit/tree/lib.php');
@@ -130,6 +132,11 @@ if ($id) {
$mform = new edit_category_form(null, array('current'=>$category, 'gpr'=>$gpr));
+$simpleform = new add_category(null, ['category' => $grade_category->id, 'courseid' => $courseid, 'gpr' => $gpr]);
+if ($simpledata = $simpleform->get_data()) {
+ $mform->set_data($simpledata);
+}
+
if ($mform->is_cancelled()) {
redirect($returnurl);
diff --git a/grade/edit/tree/item.php b/grade/edit/tree/item.php
index 88a332ad1c8..cb3b2384d63 100644
--- a/grade/edit/tree/item.php
+++ b/grade/edit/tree/item.php
@@ -23,6 +23,8 @@
*/
+use core_grades\form\add_item;
+
require_once '../../../config.php';
require_once $CFG->dirroot.'/grade/lib.php';
require_once $CFG->dirroot.'/grade/report/lib.php';
@@ -106,7 +108,7 @@ $item->cancontrolvisibility = $grade_item->can_control_visibility();
$mform = new edit_item_form(null, array('current'=>$item, 'gpr'=>$gpr));
-$simpleform = new \core_grades\form\add_item(null, ['itemid' => $grade_item->id, 'courseid' => $courseid, 'gpr' => $gpr]);
+$simpleform = new add_item(null, ['itemid' => $grade_item->id, 'courseid' => $courseid, 'gpr' => $gpr]);
if ($simpledata = $simpleform->get_data()) {
$mform->set_data($simpledata);
}
diff --git a/grade/edit/tree/outcomeitem.php b/grade/edit/tree/outcomeitem.php
index dd5185cc7ed..2d65fbe0dcc 100644
--- a/grade/edit/tree/outcomeitem.php
+++ b/grade/edit/tree/outcomeitem.php
@@ -22,6 +22,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+use core_grades\form\add_outcome;
+
require_once '../../../config.php';
require_once $CFG->dirroot.'/grade/lib.php';
require_once $CFG->dirroot.'/grade/report/lib.php';
@@ -111,6 +113,10 @@ if (empty($parent_category)) {
$mform->set_data($item);
+$simpleform = new add_outcome(null, ['itemid' => $grade_item->id, 'courseid' => $courseid, 'gpr' => $gpr]);
+if ($simpledata = $simpleform->get_data()) {
+ $mform->set_data($simpledata);
+}
if ($data = $mform->get_data()) {
diff --git a/grade/tests/behat/grade_item_pass_data_to_advanced_page.feature b/grade/tests/behat/grade_item_pass_data_to_advanced_page.feature
index 3079710dca8..809c7764ca1 100644
--- a/grade/tests/behat/grade_item_pass_data_to_advanced_page.feature
+++ b/grade/tests/behat/grade_item_pass_data_to_advanced_page.feature
@@ -17,7 +17,22 @@ Feature: We carry over data from modal to advanced grade item settings
And the following "grade categories" exist:
| fullname | course |
| Some cool grade category | C1 |
- Given I log in as "teacher1"
+ And the following config values are set as admin:
+ | enableoutcomes | 1 |
+ And the following "scales" exist:
+ | name | scale |
+ | Test Scale | Disappointing, Good, Very good, Excellent |
+ And the following "grade outcomes" exist:
+ | fullname | shortname | course | scale |
+ | Outcome 1 | OT1 | C1 | Test Scale |
+ | Outcome 2 | OT2 | C1 | Test Scale |
+ And the following "activities" exist:
+ | activity | course | idnumber | name | intro |
+ | assign | C1 | a1 | Test assignment 1 | Submit something! |
+ And I log in as "admin"
+ And I set the following administration settings values:
+ | grade_aggregations_visible | Mean of grades,Weighted mean of grades,Simple weighted mean of grades,Mean of grades (with extra credits),Median of grades,Lowest grade,Highest grade,Mode of grades,Natural |
+ And I log out
And I am on the "Course 1" course page logged in as teacher1
And I navigate to "Setup > Gradebook setup" in the course gradebook
And I press "Add grade item"
@@ -31,6 +46,25 @@ Feature: We carry over data from modal to advanced grade item settings
| Weight adjusted | 0 |
| aggregationcoef2 | 0 |
| Grade category | Course 1 |
+ And I press "Cancel"
+ And I wait until the page is ready
+ And I press "Add category"
+ And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
+ And the following fields match these values:
+ | Category name | |
+ | Aggregation | Natural |
+ | Weight adjusted | 0 |
+ | grade_item_aggregationcoef2 | 0 |
+ | Parent category | Course 1 |
+ And I press "Cancel"
+ And I wait until the page is ready
+ And I press "Add outcome item"
+ And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
+ And the following fields match these values:
+ | Item name | |
+ | Outcome | Outcome 1 |
+ | Linked activity | None |
+ | Grade category | Course 1 |
Scenario: We carry over data from modal to advanced grade item settings
Given I set the following fields to these values:
@@ -48,3 +82,35 @@ Feature: We carry over data from modal to advanced grade item settings
| Weight adjusted | 1 |
| aggregationcoef2 | 100 |
| Grade category | Some cool grade category |
+ And I press "Cancel"
+ And I wait until the page is ready
+ And I press "Add category"
+ And I set the following fields to these values:
+ | Category name | Category 1 |
+ | Aggregation | Mean of grades |
+ | Minimum grade | 1 |
+ | Maximum grade | 99 |
+ | Weight adjusted | 1 |
+ | grade_item_aggregationcoef2 | 100 |
+ | Parent category | Some cool grade category |
+ And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
+ And the following fields match these values:
+ | Category name | Category 1 |
+ | Aggregation | Mean of grades |
+ | Minimum grade | 1 |
+ | Maximum grade | 99 |
+ | Weight adjusted | 1 |
+ | grade_item_aggregationcoef2 | 100 |
+ | Parent category | Some cool grade category |
+ And I press "Cancel"
+ And I wait until the page is ready
+ And I press "Add outcome item"
+ And I set the following fields to these values:
+ | Item name | Outcome item 1 |
+ | Outcome | Outcome 2 |
+ | Linked activity | Test assignment 1 |
+ And I click on "Show more..." "link" in the ".modal-dialog" "css_element"
+ And the following fields match these values:
+ | Item name | Outcome item 1 |
+ | Outcome | Outcome 2 |
+ | Linked activity | Test assignment 1 |