diff --git a/course/classes/customfield/course_handler.php b/course/classes/customfield/course_handler.php
index c30da889e9ad6..730c01099602c 100644
--- a/course/classes/customfield/course_handler.php
+++ b/course/classes/customfield/course_handler.php
@@ -238,20 +238,4 @@ public function restore_instance_data_from_backup(\restore_task $task, array $da
}
}
}
-
- /**
- * Set up page customfield/edit.php
- *
- * @param field_controller $field
- * @return string page heading
- */
- public function setup_edit_page(field_controller $field) : string {
- global $CFG, $PAGE;
- require_once($CFG->libdir.'/adminlib.php');
-
- $title = parent::setup_edit_page($field);
- admin_externalpage_setup('course_customfield');
- $PAGE->navbar->add($title);
- return $title;
- }
}
diff --git a/course/tests/behat/customfields_locked.feature b/course/tests/behat/customfields_locked.feature
index 45d55dd3358f7..9a06bd1cf4d3c 100644
--- a/course/tests/behat/customfields_locked.feature
+++ b/course/tests/behat/customfields_locked.feature
@@ -1,5 +1,5 @@
-@core @core_course @core_customfield
-Feature: Fields locked control where they are displayed
+@core @core_course @core_customfield @javascript
+Feature: Fields locked control who is able to edit it
In order to display custom fields on course listing
As a manager
I can change the visibility of the fields
@@ -19,12 +19,40 @@ Feature: Fields locked control where they are displayed
| user | course | role |
| teacher1 | C1 | editingteacher |
- Scenario: Display course custom fields on homepage
+ Scenario: Editing locked and not locked custom fields
When I log in as "admin"
And I navigate to "Courses > Course custom fields" in site administration
And I click on "Add a new custom field" "link"
And I click on "Short text" "link"
And I set the following fields to these values:
- | Name | Test field |
- | Short name | testfield |
- | Locked | No |
+ | Name | Test field1 |
+ | Short name | testfield1 |
+ | Locked | No |
+ And I click on "Save changes" "button" in the "Adding a new Short text" "dialogue"
+ And I click on "Add a new custom field" "link"
+ And I click on "Short text" "link"
+ And I set the following fields to these values:
+ | Name | Test field2 |
+ | Short name | testfield2 |
+ | Locked | Yes |
+ And I click on "Save changes" "button" in the "Adding a new Short text" "dialogue"
+ And I am on "Course 1" course homepage
+ And I navigate to "Edit settings" in current page administration
+ And I set the following fields to these values:
+ | Test field1 | testcontent1 |
+ | Test field2 | testcontent2 |
+ And I press "Save and display"
+ And I am on site homepage
+ Then I should see "Test field1: testcontent1"
+ And I should see "Test field2: testcontent2"
+ And I log out
+ And I log in as "teacher1"
+ And I am on "Course 1" course homepage
+ And I navigate to "Edit settings" in current page administration
+ And I expand all fieldsets
+ And the field "Test field1" matches value "testcontent1"
+ And I should not see "Test field2"
+ And I press "Save and display"
+ And I am on site homepage
+ And I should see "Test field1: testcontent1"
+ And I should see "Test field2: testcontent2"
diff --git a/course/tests/behat/customfields_visibility.feature b/course/tests/behat/customfields_visibility.feature
index 802f6fa5871bf..d4b6d08266465 100644
--- a/course/tests/behat/customfields_visibility.feature
+++ b/course/tests/behat/customfields_visibility.feature
@@ -1,4 +1,4 @@
-@core @core_course @core_customfield
+@core @core_course @core_customfield @javascript
Feature: The visibility of fields control where they are displayed
In order to display custom fields on course listing
As a manager
@@ -28,7 +28,7 @@ Feature: The visibility of fields control where they are displayed
| Name | Test field |
| Short name | testfield |
| Visible to | Everyone |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Short text" "dialogue"
And I log out
Then I log in as "teacher1"
And I am on "Course 1" course homepage
@@ -48,7 +48,7 @@ Feature: The visibility of fields control where they are displayed
| Name | Test field |
| Short name | testfield |
| Visible to | Nobody |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Short text" "dialogue"
And I log out
When I log in as "teacher1"
And I am on "Course 1" course homepage
@@ -68,7 +68,7 @@ Feature: The visibility of fields control where they are displayed
| Name | Test field |
| Short name | testfield |
| Visible to | Teachers |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Short text" "dialogue"
And I log out
When I log in as "teacher1"
And I am on "Course 1" course homepage
diff --git a/customfield/amd/build/form.min.js b/customfield/amd/build/form.min.js
index 84d91f9336bb3..3e8fc457c4096 100644
--- a/customfield/amd/build/form.min.js
+++ b/customfield/amd/build/form.min.js
@@ -1,2 +1,2 @@
-define ("core_customfield/form",["jquery","core/str","core/notification","core/ajax","core/templates","core/sortable_list","core/inplace_editable"],function(a,b,c,d,e,f){var g=function(f,g,h,i,j){b.get_strings([{key:"confirm"},{key:"confirmdelete"+g,component:"core_customfield"},{key:"yes"},{key:"no"}]).done(function(b){c.confirm(b[0],b[1],b[2],b[3],function(){var b="field"===g?"core_customfield_delete_field":"core_customfield_delete_category";d.call([{methodname:b,args:{id:f}},{methodname:"core_customfield_reload_template",args:{component:h,area:i,itemid:j}}])[1].then(function(a){return e.render("core_customfield/list",a)}).then(function(b,c){e.replaceNode(a("[data-region=\"list-page\"]"),b,c);return null}).fail(c.exception)})}).fail(c.exception)},h=function(b,f,g){var h=d.call([{methodname:"core_customfield_create_category",args:{component:b,area:f,itemid:g}},{methodname:"core_customfield_reload_template",args:{component:b,area:f,itemid:g}}]),i;h[0].then(function(a){i=a;return null}).fail(c.exception);h[1].then(function(a){return e.render("core_customfield/list",a)}).then(function(b,c){e.replaceNode(a("[data-region=\"list-page\"]"),b,c);window.location.href="#category-"+i;return null}).fail(c.exception)};return{init:function init(){var e=a("#customfield_catlist"),i=e.attr("data-component"),j=e.attr("data-area"),k=e.attr("data-itemid");a("[data-role=deletefield]").on("click",function(b){g(a(this).attr("data-id"),"field",i,j,k);b.preventDefault()});a("[data-role=deletecategory]").on("click",function(b){g(a(this).attr("data-id"),"category",i,j,k);b.preventDefault()});a("[data-role=addnewcategory]").on("click",function(){h(i,j,k)});var l=function(a){return a.closest("[data-category-id]").find("[data-inplaceeditable][data-itemtype=category][data-component=core_customfield]").attr("data-value")},m=new f(a("#customfield_catlist .categorieslist"),{moveHandlerSelector:".movecategory [data-drag-type=move]"});m.getElementName=function(b){return a.Deferred().resolve(l(b))};a("[data-category-id]").on("sortablelist-drop",function(a,b){if(b.positionChanged){var e=d.call([{methodname:"core_customfield_move_category",args:{id:b.element.data("category-id"),beforeid:b.targetNextElement.data("category-id")}}]);e[0].fail(c.exception)}a.stopPropagation()});var n=new f(a("#customfield_catlist .fieldslist tbody"),{moveHandlerSelector:".movefield [data-drag-type=move]"});n.getDestinationName=function(c,d){if(!d.length){return b.get_string("totopofcategory","customfield",l(c))}else if(d.attr("data-field-name")){return b.get_string("afterfield","customfield",d.attr("data-field-name"))}else{return a.Deferred().resolve("")}};a("[data-field-name]").on("sortablelist-drop",function(a,b){a.stopPropagation();if(b.positionChanged){var e=d.call([{methodname:"core_customfield_move_field",args:{id:b.element.data("field-id"),beforeid:b.targetNextElement.data("field-id"),categoryid:+b.targetList.closest("[data-category-id]").attr("data-category-id")}}]);e[0].fail(c.exception)}}).on("sortablelist-drag",function(d){d.stopPropagation();b.get_string("therearenofields","core_customfield").then(function(b){a("#customfield_catlist .categorieslist").children().each(function(){var c=a(this).find(a(".field")),d=a(this).find(a(".nofields"));if(!c.length&&!d.length){a(this).find("tbody").append("
"+b+" |
")}if(c.length&&d.length){d.remove()}});return null}).fail(c.exception)});a("[data-category-id], [data-field-name]").on("sortablelist-dragstart",function(b,c){setTimeout(function(){a(".sortable-list-is-dragged").width(c.element.width())},501)})}}});
+define ("core_customfield/form",["jquery","core/str","core/notification","core/ajax","core/templates","core/sortable_list","core_form/modalform","core/inplace_editable"],function(a,b,c,d,e,f,g){var h=function(f,g,h,i,j){b.get_strings([{key:"confirm"},{key:"confirmdelete"+g,component:"core_customfield"},{key:"yes"},{key:"no"}]).done(function(b){c.confirm(b[0],b[1],b[2],b[3],function(){var b="field"===g?"core_customfield_delete_field":"core_customfield_delete_category";d.call([{methodname:b,args:{id:f}},{methodname:"core_customfield_reload_template",args:{component:h,area:i,itemid:j}}])[1].then(function(a){return e.render("core_customfield/list",a)}).then(function(b,c){e.replaceNode(a("[data-region=\"list-page\"]"),b,c);return null}).fail(c.exception)})}).fail(c.exception)},i=function(b,f,g){var h=d.call([{methodname:"core_customfield_create_category",args:{component:b,area:f,itemid:g}},{methodname:"core_customfield_reload_template",args:{component:b,area:f,itemid:g}}]),i;h[0].then(function(a){i=a;return null}).fail(c.exception);h[1].then(function(a){return e.render("core_customfield/list",a)}).then(function(b,c){e.replaceNode(a("[data-region=\"list-page\"]"),b,c);window.location.href="#category-"+i;return null}).fail(c.exception)},j=function(a){var c=a.closest(".action-menu").querySelector(".dropdown-toggle"),d=new g({formClass:"core_customfield\\field_config_form",args:{categoryid:a.getAttribute("data-categoryid"),type:a.getAttribute("data-type")},modalConfig:{title:b.get_string("addingnewcustomfield","core_customfield",a.getAttribute("data-typename"))},returnFocus:c});d.addEventListener(d.events.FORM_SUBMITTED,function(){return window.location.reload()});d.show()},k=function(a){var c=new g({formClass:"core_customfield\\field_config_form",args:{id:a.getAttribute("data-id")},modalConfig:{title:b.get_string("editingfield","core_customfield",a.getAttribute("data-name"))},returnFocus:a});c.addEventListener(c.events.FORM_SUBMITTED,function(){return window.location.reload()});c.show()};return{init:function init(){var e=a("#customfield_catlist"),g=e.attr("data-component"),l=e.attr("data-area"),m=e.attr("data-itemid");a("[data-role=deletefield]").on("click",function(b){h(a(this).attr("data-id"),"field",g,l,m);b.preventDefault()});a("[data-role=deletecategory]").on("click",function(b){h(a(this).attr("data-id"),"category",g,l,m);b.preventDefault()});a("[data-role=addnewcategory]").on("click",function(){i(g,l,m)});a("[data-role=addfield]").on("click",function(a){j(a.currentTarget);a.preventDefault()});a("[data-role=editfield]").on("click",function(a){k(a.currentTarget);a.preventDefault()});var n=function(a){return a.closest("[data-category-id]").find("[data-inplaceeditable][data-itemtype=category][data-component=core_customfield]").attr("data-value")},o=new f(a("#customfield_catlist .categorieslist"),{moveHandlerSelector:".movecategory [data-drag-type=move]"});o.getElementName=function(b){return a.Deferred().resolve(n(b))};a("[data-category-id]").on("sortablelist-drop",function(a,b){if(b.positionChanged){var e=d.call([{methodname:"core_customfield_move_category",args:{id:b.element.data("category-id"),beforeid:b.targetNextElement.data("category-id")}}]);e[0].fail(c.exception)}a.stopPropagation()});var p=new f(a("#customfield_catlist .fieldslist tbody"),{moveHandlerSelector:".movefield [data-drag-type=move]"});p.getDestinationName=function(c,d){if(!d.length){return b.get_string("totopofcategory","customfield",n(c))}else if(d.attr("data-field-name")){return b.get_string("afterfield","customfield",d.attr("data-field-name"))}else{return a.Deferred().resolve("")}};a("[data-field-name]").on("sortablelist-drop",function(a,b){a.stopPropagation();if(b.positionChanged){var e=d.call([{methodname:"core_customfield_move_field",args:{id:b.element.data("field-id"),beforeid:b.targetNextElement.data("field-id"),categoryid:+b.targetList.closest("[data-category-id]").attr("data-category-id")}}]);e[0].fail(c.exception)}}).on("sortablelist-drag",function(d){d.stopPropagation();b.get_string("therearenofields","core_customfield").then(function(b){a("#customfield_catlist .categorieslist").children().each(function(){var c=a(this).find(a(".field")),d=a(this).find(a(".nofields"));if(!c.length&&!d.length){a(this).find("tbody").append(""+b+" |
")}if(c.length&&d.length){d.remove()}});return null}).fail(c.exception)});a("[data-category-id], [data-field-name]").on("sortablelist-dragstart",function(b,c){setTimeout(function(){a(".sortable-list-is-dragged").width(c.element.width())},501)})}}});
//# sourceMappingURL=form.min.js.map
diff --git a/customfield/amd/build/form.min.js.map b/customfield/amd/build/form.min.js.map
index 70d8bd3fba19d..c952fd3441e3b 100644
--- a/customfield/amd/build/form.min.js.map
+++ b/customfield/amd/build/form.min.js.map
@@ -1 +1 @@
-{"version":3,"sources":["../src/form.js"],"names":["define","$","Str","Notification","Ajax","Templates","SortableList","confirmDelete","id","type","component","area","itemid","get_strings","done","s","confirm","func","call","methodname","args","then","response","render","html","js","replaceNode","fail","exception","createNewCategory","promises","categoryid","window","location","href","init","mainlist","attr","on","e","preventDefault","categoryName","element","closest","find","sortCat","moveHandlerSelector","getElementName","el","Deferred","resolve","evt","info","positionChanged","data","beforeid","targetNextElement","stopPropagation","sort","getDestinationName","parentElement","afterElement","length","get_string","targetList","children","each","fields","nofields","append","remove","setTimeout","width"],"mappings":"AAuBAA,OAAM,yBAAC,CAAC,QAAD,CAAW,UAAX,CAAuB,mBAAvB,CAA4C,WAA5C,CAAyD,gBAAzD,CAA2E,oBAA3E,CAAiG,uBAAjG,CAAD,CACF,SACIC,CADJ,CACOC,CADP,C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,WAAD,CAAd,CADf,CAEA,GAAI,CAACkE,CAAM,CAACL,MAAR,EAAkB,CAACM,CAAQ,CAACN,MAAhC,CAAwC,CACpC7D,CAAC,CAAC,IAAD,CAAD,CAAQ2C,IAAR,CAAa,OAAb,EAAsByB,MAAtB,CACI,4CAA0CtD,CAA1C,CAA8C,YADlD,CAGH,CACD,GAAIoD,CAAM,CAACL,MAAP,EAAiBM,CAAQ,CAACN,MAA9B,CAAsC,CAClCM,CAAQ,CAACE,MAAT,EACH,CACJ,CAXD,EAYA,MAAO,KACV,CAdD,EAcG3C,IAdH,CAcQxB,CAAY,CAACyB,SAdrB,CAeH,CAjCD,EAmCA3B,CAAC,CAAC,uCAAD,CAAD,CAA2CqC,EAA3C,CAA8C,wBAA9C,CACI,SAASa,CAAT,CAAcC,CAAd,CAAoB,CAChBmB,UAAU,CAAC,UAAW,CAClBtE,CAAC,CAAC,2BAAD,CAAD,CAA+BuE,KAA/B,CAAqCpB,CAAI,CAACV,OAAL,CAAa8B,KAAb,EAArC,CACH,CAFS,CAEP,GAFO,CAGb,CALL,CAQH,CAlHE,CAoHV,CAnLK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * This module depends on the real jquery - and returns the non-global version of it.\n *\n * @module core_customfield/form\n * @package core_customfield\n * @copyright 2018 Toni Barbera\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates', 'core/sortable_list', 'core/inplace_editable'],\n function(\n $, Str, Notification, Ajax, Templates, SortableList) {\n\n /**\n * Display confirmation dialogue\n *\n * @param {Number} id\n * @param {String} type\n * @param {String} component\n * @param {String} area\n * @param {Number} itemid\n */\n var confirmDelete = function(id, type, component, area, itemid) {\n Str.get_strings([\n {'key': 'confirm'},\n {'key': 'confirmdelete' + type, component: 'core_customfield'},\n {'key': 'yes'},\n {'key': 'no'},\n ]).done(function(s) {\n Notification.confirm(s[0], s[1], s[2], s[3], function() {\n var func = (type === 'field') ? 'core_customfield_delete_field' : 'core_customfield_delete_category';\n Ajax.call([\n {methodname: func, args: {id: id}},\n {methodname: 'core_customfield_reload_template', args: {component: component, area: area, itemid: itemid}}\n ])[1].then(function(response) {\n return Templates.render('core_customfield/list', response);\n }).then(function(html, js) {\n Templates.replaceNode($('[data-region=\"list-page\"]'), html, js);\n return null;\n }).fail(Notification.exception);\n });\n }).fail(Notification.exception);\n };\n\n /**\n * Creates a new custom fields category with default name and updates the list\n *\n * @param {String} component\n * @param {String} area\n * @param {Number} itemid\n */\n var createNewCategory = function(component, area, itemid) {\n var promises = Ajax.call([\n {methodname: 'core_customfield_create_category', args: {component: component, area: area, itemid: itemid}},\n {methodname: 'core_customfield_reload_template', args: {component: component, area: area, itemid: itemid}}\n ]),\n categoryid;\n\n promises[0].then(function(response) {\n categoryid = response;\n return null;\n }).fail(Notification.exception);\n\n promises[1].then(function(response) {\n return Templates.render('core_customfield/list', response);\n }).then(function(html, js) {\n Templates.replaceNode($('[data-region=\"list-page\"]'), html, js);\n window.location.href = '#category-' + categoryid;\n return null;\n }).fail(Notification.exception);\n };\n\n return {\n /**\n * Initialise the custom fields manager\n */\n init: function() {\n var mainlist = $('#customfield_catlist'),\n component = mainlist.attr('data-component'),\n area = mainlist.attr('data-area'),\n itemid = mainlist.attr('data-itemid');\n $(\"[data-role=deletefield]\").on('click', function(e) {\n confirmDelete($(this).attr('data-id'), 'field', component, area, itemid);\n e.preventDefault();\n });\n $(\"[data-role=deletecategory]\").on('click', function(e) {\n confirmDelete($(this).attr('data-id'), 'category', component, area, itemid);\n e.preventDefault();\n });\n $('[data-role=addnewcategory]').on('click', function() {\n createNewCategory(component, area, itemid);\n });\n\n var categoryName = function(element) {\n return element\n .closest('[data-category-id]')\n .find('[data-inplaceeditable][data-itemtype=category][data-component=core_customfield]')\n .attr('data-value');\n };\n\n // Sort category.\n var sortCat = new SortableList(\n $('#customfield_catlist .categorieslist'),\n {moveHandlerSelector: '.movecategory [data-drag-type=move]'}\n );\n\n sortCat.getElementName = function(el) {\n return $.Deferred().resolve(categoryName(el));\n };\n\n $('[data-category-id]').on('sortablelist-drop', function(evt, info) {\n if (info.positionChanged) {\n var promises = Ajax.call([\n {\n methodname: 'core_customfield_move_category',\n args: {\n id: info.element.data('category-id'),\n beforeid: info.targetNextElement.data('category-id')\n }\n\n },\n ]);\n promises[0].fail(Notification.exception);\n }\n evt.stopPropagation(); // Important for nested lists to prevent multiple targets.\n });\n\n // Sort fields.\n var sort = new SortableList(\n $('#customfield_catlist .fieldslist tbody'),\n {moveHandlerSelector: '.movefield [data-drag-type=move]'}\n );\n\n sort.getDestinationName = function(parentElement, afterElement) {\n if (!afterElement.length) {\n return Str.get_string('totopofcategory', 'customfield', categoryName(parentElement));\n } else if (afterElement.attr('data-field-name')) {\n return Str.get_string('afterfield', 'customfield', afterElement.attr('data-field-name'));\n } else {\n return $.Deferred().resolve('');\n }\n };\n\n $('[data-field-name]').on('sortablelist-drop', function(evt, info) {\n evt.stopPropagation(); // Important for nested lists to prevent multiple targets.\n if (info.positionChanged) {\n var promises = Ajax.call([\n {\n methodname: 'core_customfield_move_field',\n args: {\n id: info.element.data('field-id'),\n beforeid: info.targetNextElement.data('field-id'),\n categoryid: Number(info.targetList.closest('[data-category-id]').attr('data-category-id'))\n },\n },\n ]);\n promises[0].fail(Notification.exception);\n }\n }).on('sortablelist-drag', function(evt) {\n evt.stopPropagation(); // Important for nested lists to prevent multiple targets.\n // Refreshing fields tables.\n Str.get_string('therearenofields', 'core_customfield').then(function(s) {\n $('#customfield_catlist .categorieslist').children().each(function() {\n var fields = $(this).find($('.field')),\n nofields = $(this).find($('.nofields'));\n if (!fields.length && !nofields.length) {\n $(this).find('tbody').append(\n '' + s + ' |
'\n );\n }\n if (fields.length && nofields.length) {\n nofields.remove();\n }\n });\n return null;\n }).fail(Notification.exception);\n });\n\n $('[data-category-id], [data-field-name]').on('sortablelist-dragstart',\n function(evt, info) {\n setTimeout(function() {\n $('.sortable-list-is-dragged').width(info.element.width());\n }, 501);\n }\n );\n\n }\n };\n});\n"],"file":"form.min.js"}
\ No newline at end of file
+{"version":3,"sources":["../src/form.js"],"names":["define","$","Str","Notification","Ajax","Templates","SortableList","ModalForm","confirmDelete","id","type","component","area","itemid","get_strings","done","s","confirm","func","call","methodname","args","then","response","render","html","js","replaceNode","fail","exception","createNewCategory","promises","categoryid","window","location","href","createNewField","element","returnFocus","closest","querySelector","form","formClass","getAttribute","modalConfig","title","get_string","addEventListener","events","FORM_SUBMITTED","reload","show","editField","init","mainlist","attr","on","e","preventDefault","currentTarget","categoryName","find","sortCat","moveHandlerSelector","getElementName","el","Deferred","resolve","evt","info","positionChanged","data","beforeid","targetNextElement","stopPropagation","sort","getDestinationName","parentElement","afterElement","length","targetList","children","each","fields","nofields","append","remove","setTimeout","width"],"mappings":"AAuBAA,OAAM,yBAAC,CAAC,QAAD,CAAW,UAAX,CAAuB,mBAAvB,CAA4C,WAA5C,CAAyD,gBAAzD,CAA2E,oBAA3E,CACC,qBADD,CACwB,uBADxB,CAAD,CAEF,SACIC,CADJ,CACOC,CADP,CACYC,CADZ,CAC0BC,CAD1B,CACgCC,CADhC,CAC2CC,CAD3C,CACyDC,CADzD,CACoE,IAWhEC,CAAAA,CAAa,CAAG,SAASC,CAAT,CAAaC,CAAb,CAAmBC,CAAnB,CAA8BC,CAA9B,CAAoCC,CAApC,CAA4C,CAC5DX,CAAG,CAACY,WAAJ,CAAgB,CACZ,CAAC,IAAO,SAAR,CADY,CAEZ,CAAC,IAAO,gBAA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AM,CAAGlF,CAAC,CAAC,IAAD,CAAD,CAAQ4D,IAAR,CAAa5D,CAAC,CAAC,QAAD,CAAd,CAAb,CACImF,CAAQ,CAAGnF,CAAC,CAAC,IAAD,CAAD,CAAQ4D,IAAR,CAAa5D,CAAC,CAAC,WAAD,CAAd,CADf,CAEA,GAAI,CAACkF,CAAM,CAACJ,MAAR,EAAkB,CAACK,CAAQ,CAACL,MAAhC,CAAwC,CACpC9E,CAAC,CAAC,IAAD,CAAD,CAAQ4D,IAAR,CAAa,OAAb,EAAsBwB,MAAtB,CACI,4CAA0CrE,CAA1C,CAA8C,YADlD,CAGH,CACD,GAAImE,CAAM,CAACJ,MAAP,EAAiBK,CAAQ,CAACL,MAA9B,CAAsC,CAClCK,CAAQ,CAACE,MAAT,EACH,CACJ,CAXD,EAYA,MAAO,KACV,CAdD,EAcG1D,IAdH,CAcQzB,CAAY,CAAC0B,SAdrB,CAeH,CAjCD,EAmCA5B,CAAC,CAAC,uCAAD,CAAD,CAA2CuD,EAA3C,CAA8C,wBAA9C,CACI,SAASY,CAAT,CAAcC,CAAd,CAAoB,CAChBkB,UAAU,CAAC,UAAW,CAClBtF,CAAC,CAAC,2BAAD,CAAD,CAA+BuF,KAA/B,CAAqCnB,CAAI,CAAChC,OAAL,CAAamD,KAAb,EAArC,CACH,CAFS,CAEP,GAFO,CAGb,CALL,CAQH,CA1HE,CA4HV,CAtOK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * This module depends on the real jquery - and returns the non-global version of it.\n *\n * @module core_customfield/form\n * @package core_customfield\n * @copyright 2018 Toni Barbera\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates', 'core/sortable_list',\n 'core_form/modalform', 'core/inplace_editable'],\n function(\n $, Str, Notification, Ajax, Templates, SortableList, ModalForm) {\n\n /**\n * Display confirmation dialogue\n *\n * @param {Number} id\n * @param {String} type\n * @param {String} component\n * @param {String} area\n * @param {Number} itemid\n */\n var confirmDelete = function(id, type, component, area, itemid) {\n Str.get_strings([\n {'key': 'confirm'},\n {'key': 'confirmdelete' + type, component: 'core_customfield'},\n {'key': 'yes'},\n {'key': 'no'},\n ]).done(function(s) {\n Notification.confirm(s[0], s[1], s[2], s[3], function() {\n var func = (type === 'field') ? 'core_customfield_delete_field' : 'core_customfield_delete_category';\n Ajax.call([\n {methodname: func, args: {id: id}},\n {methodname: 'core_customfield_reload_template', args: {component: component, area: area, itemid: itemid}}\n ])[1].then(function(response) {\n return Templates.render('core_customfield/list', response);\n }).then(function(html, js) {\n Templates.replaceNode($('[data-region=\"list-page\"]'), html, js);\n return null;\n }).fail(Notification.exception);\n });\n }).fail(Notification.exception);\n };\n\n /**\n * Creates a new custom fields category with default name and updates the list\n *\n * @param {String} component\n * @param {String} area\n * @param {Number} itemid\n */\n var createNewCategory = function(component, area, itemid) {\n var promises = Ajax.call([\n {methodname: 'core_customfield_create_category', args: {component: component, area: area, itemid: itemid}},\n {methodname: 'core_customfield_reload_template', args: {component: component, area: area, itemid: itemid}}\n ]),\n categoryid;\n\n promises[0].then(function(response) {\n categoryid = response;\n return null;\n }).fail(Notification.exception);\n\n promises[1].then(function(response) {\n return Templates.render('core_customfield/list', response);\n }).then(function(html, js) {\n Templates.replaceNode($('[data-region=\"list-page\"]'), html, js);\n window.location.href = '#category-' + categoryid;\n return null;\n }).fail(Notification.exception);\n };\n\n /**\n * Create new custom field\n *\n * @param {HTMLElement} element\n */\n var createNewField = function(element) {\n const returnFocus = element.closest(\".action-menu\").querySelector(\".dropdown-toggle\");\n const form = new ModalForm({\n formClass: \"core_customfield\\\\field_config_form\",\n args: {\n categoryid: element.getAttribute('data-categoryid'),\n type: element.getAttribute('data-type'),\n },\n modalConfig: {\n title: Str.get_string('addingnewcustomfield', 'core_customfield', element.getAttribute('data-typename')),\n },\n returnFocus,\n });\n form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());\n form.show();\n };\n\n /**\n * Edit custom field\n *\n * @param {HTMLElement} element\n */\n var editField = function(element) {\n const form = new ModalForm({\n formClass: \"core_customfield\\\\field_config_form\",\n args: {\n id: element.getAttribute('data-id'),\n },\n modalConfig: {\n title: Str.get_string('editingfield', 'core_customfield', element.getAttribute('data-name')),\n },\n returnFocus: element,\n });\n form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());\n form.show();\n };\n\n return {\n /**\n * Initialise the custom fields manager\n */\n init: function() {\n var mainlist = $('#customfield_catlist'),\n component = mainlist.attr('data-component'),\n area = mainlist.attr('data-area'),\n itemid = mainlist.attr('data-itemid');\n $(\"[data-role=deletefield]\").on('click', function(e) {\n confirmDelete($(this).attr('data-id'), 'field', component, area, itemid);\n e.preventDefault();\n });\n $(\"[data-role=deletecategory]\").on('click', function(e) {\n confirmDelete($(this).attr('data-id'), 'category', component, area, itemid);\n e.preventDefault();\n });\n $('[data-role=addnewcategory]').on('click', function() {\n createNewCategory(component, area, itemid);\n });\n $('[data-role=addfield]').on('click', function(e) {\n createNewField(e.currentTarget);\n e.preventDefault();\n });\n $('[data-role=editfield]').on('click', function(e) {\n editField(e.currentTarget);\n e.preventDefault();\n });\n\n var categoryName = function(element) {\n return element\n .closest('[data-category-id]')\n .find('[data-inplaceeditable][data-itemtype=category][data-component=core_customfield]')\n .attr('data-value');\n };\n\n // Sort category.\n var sortCat = new SortableList(\n $('#customfield_catlist .categorieslist'),\n {moveHandlerSelector: '.movecategory [data-drag-type=move]'}\n );\n\n sortCat.getElementName = function(el) {\n return $.Deferred().resolve(categoryName(el));\n };\n\n $('[data-category-id]').on('sortablelist-drop', function(evt, info) {\n if (info.positionChanged) {\n var promises = Ajax.call([\n {\n methodname: 'core_customfield_move_category',\n args: {\n id: info.element.data('category-id'),\n beforeid: info.targetNextElement.data('category-id')\n }\n\n },\n ]);\n promises[0].fail(Notification.exception);\n }\n evt.stopPropagation(); // Important for nested lists to prevent multiple targets.\n });\n\n // Sort fields.\n var sort = new SortableList(\n $('#customfield_catlist .fieldslist tbody'),\n {moveHandlerSelector: '.movefield [data-drag-type=move]'}\n );\n\n sort.getDestinationName = function(parentElement, afterElement) {\n if (!afterElement.length) {\n return Str.get_string('totopofcategory', 'customfield', categoryName(parentElement));\n } else if (afterElement.attr('data-field-name')) {\n return Str.get_string('afterfield', 'customfield', afterElement.attr('data-field-name'));\n } else {\n return $.Deferred().resolve('');\n }\n };\n\n $('[data-field-name]').on('sortablelist-drop', function(evt, info) {\n evt.stopPropagation(); // Important for nested lists to prevent multiple targets.\n if (info.positionChanged) {\n var promises = Ajax.call([\n {\n methodname: 'core_customfield_move_field',\n args: {\n id: info.element.data('field-id'),\n beforeid: info.targetNextElement.data('field-id'),\n categoryid: Number(info.targetList.closest('[data-category-id]').attr('data-category-id'))\n },\n },\n ]);\n promises[0].fail(Notification.exception);\n }\n }).on('sortablelist-drag', function(evt) {\n evt.stopPropagation(); // Important for nested lists to prevent multiple targets.\n // Refreshing fields tables.\n Str.get_string('therearenofields', 'core_customfield').then(function(s) {\n $('#customfield_catlist .categorieslist').children().each(function() {\n var fields = $(this).find($('.field')),\n nofields = $(this).find($('.nofields'));\n if (!fields.length && !nofields.length) {\n $(this).find('tbody').append(\n '' + s + ' |
'\n );\n }\n if (fields.length && nofields.length) {\n nofields.remove();\n }\n });\n return null;\n }).fail(Notification.exception);\n });\n\n $('[data-category-id], [data-field-name]').on('sortablelist-dragstart',\n function(evt, info) {\n setTimeout(function() {\n $('.sortable-list-is-dragged').width(info.element.width());\n }, 501);\n }\n );\n\n }\n };\n});\n"],"file":"form.min.js"}
\ No newline at end of file
diff --git a/customfield/amd/src/form.js b/customfield/amd/src/form.js
index 644dc66cc8453..10df7e1a698e8 100644
--- a/customfield/amd/src/form.js
+++ b/customfield/amd/src/form.js
@@ -21,9 +21,10 @@
* @copyright 2018 Toni Barbera
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-define(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates', 'core/sortable_list', 'core/inplace_editable'],
+define(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates', 'core/sortable_list',
+ 'core_form/modalform', 'core/inplace_editable'],
function(
- $, Str, Notification, Ajax, Templates, SortableList) {
+ $, Str, Notification, Ajax, Templates, SortableList, ModalForm) {
/**
* Display confirmation dialogue
@@ -84,6 +85,48 @@ define(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates'
}).fail(Notification.exception);
};
+ /**
+ * Create new custom field
+ *
+ * @param {HTMLElement} element
+ */
+ var createNewField = function(element) {
+ const returnFocus = element.closest(".action-menu").querySelector(".dropdown-toggle");
+ const form = new ModalForm({
+ formClass: "core_customfield\\field_config_form",
+ args: {
+ categoryid: element.getAttribute('data-categoryid'),
+ type: element.getAttribute('data-type'),
+ },
+ modalConfig: {
+ title: Str.get_string('addingnewcustomfield', 'core_customfield', element.getAttribute('data-typename')),
+ },
+ returnFocus,
+ });
+ form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());
+ form.show();
+ };
+
+ /**
+ * Edit custom field
+ *
+ * @param {HTMLElement} element
+ */
+ var editField = function(element) {
+ const form = new ModalForm({
+ formClass: "core_customfield\\field_config_form",
+ args: {
+ id: element.getAttribute('data-id'),
+ },
+ modalConfig: {
+ title: Str.get_string('editingfield', 'core_customfield', element.getAttribute('data-name')),
+ },
+ returnFocus: element,
+ });
+ form.addEventListener(form.events.FORM_SUBMITTED, () => window.location.reload());
+ form.show();
+ };
+
return {
/**
* Initialise the custom fields manager
@@ -104,6 +147,14 @@ define(['jquery', 'core/str', 'core/notification', 'core/ajax', 'core/templates'
$('[data-role=addnewcategory]').on('click', function() {
createNewCategory(component, area, itemid);
});
+ $('[data-role=addfield]').on('click', function(e) {
+ createNewField(e.currentTarget);
+ e.preventDefault();
+ });
+ $('[data-role=editfield]').on('click', function(e) {
+ editField(e.currentTarget);
+ e.preventDefault();
+ });
var categoryName = function(element) {
return element
diff --git a/customfield/classes/field_config_form.php b/customfield/classes/field_config_form.php
index 06a6c40fcbf5c..3d5d8bf73174d 100644
--- a/customfield/classes/field_config_form.php
+++ b/customfield/classes/field_config_form.php
@@ -26,9 +26,6 @@
defined('MOODLE_INTERNAL') || die;
-global $CFG;
-require_once($CFG->libdir . '/formslib.php');
-
/**
* Class field_config_form
*
@@ -36,7 +33,10 @@
* @copyright 2018 David Matamoros
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class field_config_form extends \moodleform {
+class field_config_form extends \core_form\dynamic_form {
+
+ /** @var field_controller */
+ protected $field;
/**
* Class definition
@@ -44,13 +44,9 @@ class field_config_form extends \moodleform {
* @throws \coding_exception
*/
public function definition() {
- global $PAGE;
$mform = $this->_form;
- $field = $this->_customdata['field'];
- if (!($field && $field instanceof field_controller)) {
- throw new \coding_exception('Field must be passed in customdata');
- }
+ $field = $this->get_field();
$handler = $field->get_handler();
$mform->addElement('header', '_commonsettings', get_string('commonsettings', 'core_customfield'));
@@ -97,7 +93,7 @@ public function definition() {
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
- $this->add_action_buttons(true);
+ // This form is only used inside modal dialogues and never needs action buttons.
}
/**
@@ -111,8 +107,7 @@ public function validation($data, $files = array()) {
global $DB;
$errors = array();
- /** @var field_controller $field */
- $field = $this->_customdata['field'];
+ $field = $this->get_field();
$handler = $field->get_handler();
// Check the shortname is specified and is unique for this component-area-itemid combination.
@@ -131,4 +126,89 @@ public function validation($data, $files = array()) {
return $errors;
}
+
+ /**
+ * Get field
+ *
+ * @return field_controller
+ * @throws \moodle_exception
+ */
+ protected function get_field(): field_controller {
+ if ($this->field === null) {
+ if (!empty($this->_ajaxformdata['id'])) {
+ $this->field = \core_customfield\field_controller::create((int)$this->_ajaxformdata['id']);
+ } else if (!empty($this->_ajaxformdata['categoryid']) && !empty($this->_ajaxformdata['type'])) {
+ $category = \core_customfield\category_controller::create((int)$this->_ajaxformdata['categoryid']);
+ $type = clean_param($this->_ajaxformdata['type'], PARAM_PLUGIN);
+ $this->field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
+ } else {
+ throw new \moodle_exception('fieldnotfound', 'core_customfield');
+ }
+ }
+ return $this->field;
+ }
+
+ /**
+ * Check if current user has access to this form, otherwise throw exception
+ *
+ * Sometimes permission check may depend on the action and/or id of the entity.
+ * If necessary, form data is available in $this->_ajaxformdata
+ */
+ protected function check_access_for_dynamic_submission(): void {
+ $field = $this->get_field();
+ $handler = $field->get_handler();
+ if (!$handler->can_configure()) {
+ print_error('nopermissionconfigure', 'core_customfield');
+ }
+ }
+
+ /**
+ * Load in existing data as form defaults
+ *
+ * Can be overridden to retrieve existing values from db by entity id and also
+ * to preprocess editor and filemanager elements
+ *
+ * Example:
+ * $this->set_data(get_entity($this->_ajaxformdata['id']));
+ */
+ public function set_data_for_dynamic_submission(): void {
+ $this->set_data(api::prepare_field_for_config_form($this->get_field()));
+ }
+
+ /**
+ * Process the form submission
+ *
+ * This method can return scalar values or arrays that can be json-encoded, they will be passed to the caller JS.
+ *
+ * @return mixed
+ */
+ public function process_dynamic_submission() {
+ $data = $this->get_data();
+ $field = $this->get_field();
+ $handler = $field->get_handler();
+ $handler->save_field_configuration($field, $data);
+ return null;
+ }
+
+ /**
+ * Form context
+ * @return \context
+ */
+ protected function get_context_for_dynamic_submission(): \context {
+ return $this->get_field()->get_handler()->get_configuration_context();
+ }
+
+ /**
+ * Page url
+ * @return \moodle_url
+ */
+ protected function get_page_url_for_dynamic_submission(): \moodle_url {
+ $field = $this->get_field();
+ if ($field->get('id')) {
+ $params = ['action' => 'editfield', 'id' => $field->get('id')];
+ } else {
+ $params = ['action' => 'addfield', 'categoryid' => $field->get('categoryid'), 'type' => $field->get('type')];
+ }
+ return new \moodle_url($field->get_handler()->get_configuration_url(), $params);
+ }
}
diff --git a/customfield/classes/handler.php b/customfield/classes/handler.php
index 023f0d29ad0bc..650be9daedc06 100644
--- a/customfield/classes/handler.php
+++ b/customfield/classes/handler.php
@@ -178,18 +178,6 @@ public function uses_categories() : bool {
return true;
}
- /**
- * The form to create or edit a field
- *
- * @param field_controller $field
- * @return field_config_form
- */
- public function get_field_config_form(field_controller $field) : field_config_form {
- $form = new field_config_form(null, ['field' => $field]);
- $form->set_data(api::prepare_field_for_config_form($field));
- return $form;
- }
-
/**
* Generates a name for the new category
*
@@ -798,52 +786,4 @@ public function delete_instance(int $instanceid) {
$data->delete();
}
}
-
- /**
- * Set up page customfield/edit.php
- *
- * Handler should override this method and set page context
- *
- * @param field_controller $field
- * @return string page heading
- */
- public function setup_edit_page(field_controller $field) : string {
- global $PAGE;
-
- // Page context.
- $context = $this->get_configuration_context();
- if ($context->contextlevel == CONTEXT_MODULE) {
- list($course, $cm) = get_course_and_cm_from_cmid($context->instanceid, '', $context->get_course_context()->instanceid);
- require_login($course, false, $cm);
- } else if ($context->contextlevel == CONTEXT_COURSE) {
- require_login($context->instanceid, false);
- } else {
- $PAGE->set_context(null); // This will set to system context only if the context was not set before.
- if ($PAGE->context->id != $context->id) {
- // In case of user or block context level this method must be overridden.
- debugging('Handler must override setup_edit_page() and set the page context before calling parent method.',
- DEBUG_DEVELOPER);
- }
- }
-
- // Set up url and title.
- if ($field->get('id')) {
- $field = $this->validate_field($field);
- } else {
- $this->validate_category($field->get_category());
- }
- $url = new \moodle_url('/customfield/edit.php',
- ['id' => $field->get('id'), 'type' => $field->get('type'), 'categoryid' => $field->get('categoryid')]);
-
- $PAGE->set_url($url);
- $typestr = get_string('pluginname', 'customfield_' . $field->get('type'));
- if ($field->get('id')) {
- $title = get_string('editingfield', 'core_customfield',
- $field->get_formatted_name());
- } else {
- $title = get_string('addingnewcustomfield', 'core_customfield', $typestr);
- }
- $PAGE->set_title($title);
- return $title;
- }
}
diff --git a/customfield/classes/output/management.php b/customfield/classes/output/management.php
index e451b275c5bec..c6e74174deac9 100644
--- a/customfield/classes/output/management.php
+++ b/customfield/classes/output/management.php
@@ -96,10 +96,6 @@ public function export_for_template(\renderer_base $output) {
$fieldarray['shortname'] = $field->get('shortname');
$fieldarray['movetitle'] = get_string('movefield', 'core_customfield', $fieldname);
- $fieldarray['editfieldurl'] = (new \moodle_url('/customfield/edit.php', [
- 'id' => $fieldarray['id'],
- ]))->out(false);
-
$categoryarray['fields'][] = $fieldarray;
}
@@ -107,11 +103,10 @@ public function export_for_template(\renderer_base $output) {
$menu->set_alignment(\action_menu::BL, \action_menu::BL);
$menu->set_menu_trigger(get_string('createnewcustomfield', 'core_customfield'));
- $baseaddfieldurl = new \moodle_url('/customfield/edit.php',
- array('action' => 'editfield', 'categoryid' => $category->get('id')));
foreach ($fieldtypes as $type => $fieldname) {
- $addfieldurl = new \moodle_url($baseaddfieldurl, array('type' => $type));
- $action = new \action_menu_link_secondary($addfieldurl, null, $fieldname);
+ $action = new \action_menu_link_secondary(new \moodle_url('#'), null, $fieldname,
+ ['data-role' => 'addfield', 'data-categoryid' => $category->get('id'), 'data-type' => $type,
+ 'data-typename' => $fieldname]);
$menu->add($action);
}
$menu->attributes['class'] .= ' float-left mr-1';
diff --git a/customfield/edit.php b/customfield/edit.php
deleted file mode 100644
index 1685e7e9ed435..0000000000000
--- a/customfield/edit.php
+++ /dev/null
@@ -1,61 +0,0 @@
-.
-
-/**
- * Edit configuration of a custom field
- *
- * @package core_customfield
- * @copyright 2018 David Matamoros
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-require_once(__DIR__ . '/../config.php');
-require_once($CFG->libdir . '/adminlib.php');
-
-$id = optional_param('id', 0, PARAM_INT);
-$categoryid = optional_param('categoryid', 0, PARAM_INT);
-$type = optional_param('type', null, PARAM_COMPONENT);
-
-if ($id) {
- $field = \core_customfield\field_controller::create($id);
-} else if ($categoryid && $type) {
- $category = \core_customfield\category_controller::create($categoryid);
- $field = \core_customfield\field_controller::create(0, (object)['type' => $type], $category);
-} else {
- print_error('fieldnotfound', 'core_customfield');
-}
-
-$handler = $field->get_handler();
-require_login();
-if (!$handler->can_configure()) {
- print_error('nopermissionconfigure', 'core_customfield');
-}
-$title = $handler->setup_edit_page($field);
-
-$mform = $handler->get_field_config_form($field);
-if ($mform->is_cancelled()) {
- redirect($handler->get_configuration_url());
-} else if ($data = $mform->get_data()) {
- $handler->save_field_configuration($field, $data);
- redirect($handler->get_configuration_url());
-}
-
-echo $OUTPUT->header();
-echo $OUTPUT->heading($title);
-
-$mform->display();
-
-echo $OUTPUT->footer();
diff --git a/customfield/externallib.php b/customfield/externallib.php
index 76a2f348dfe89..1f26bd89e3a23 100644
--- a/customfield/externallib.php
+++ b/customfield/externallib.php
@@ -131,7 +131,6 @@ public static function reload_template_returns() {
'name' => new external_value(PARAM_NOTAGS, 'name'),
'shortname' => new external_value(PARAM_NOTAGS, 'shortname'),
'type' => new external_value(PARAM_NOTAGS, 'type'),
- 'editfieldurl' => new external_value(PARAM_URL, 'edit field url'),
'id' => new external_value(PARAM_INT, 'id'),
)
)
diff --git a/customfield/field/checkbox/tests/behat/field.feature b/customfield/field/checkbox/tests/behat/field.feature
index e26a2feba5a79..1a99de6b32ff1 100644
--- a/customfield/field/checkbox/tests/behat/field.feature
+++ b/customfield/field/checkbox/tests/behat/field.feature
@@ -1,4 +1,4 @@
-@customfield @customfield_checkbox
+@customfield @customfield_checkbox @javascript
Feature: Managers can manage course custom fields checkbox
In order to have additional data on the course
As a manager
@@ -17,7 +17,7 @@ Feature: Managers can manage course custom fields checkbox
And I set the following fields to these values:
| Name | Test field |
| Short name | testfield |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Checkbox" "dialogue"
Then I should see "Test field"
And I log out
@@ -27,29 +27,26 @@ Feature: Managers can manage course custom fields checkbox
And I set the following fields to these values:
| Name | Test field |
| Short name | testfield |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Checkbox" "dialogue"
And I click on "Edit" "link" in the "Test field" "table_row"
And I set the following fields to these values:
| Name | Edited field |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Updating Test field" "dialogue"
Then I should see "Edited field"
And I should not see "Test field"
- And I log out
- @javascript
Scenario: Delete a custom course checkbox field
When I click on "Add a new custom field" "link"
And I click on "Checkbox" "link"
And I set the following fields to these values:
| Name | Test field |
| Short name | testfield |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Checkbox" "dialogue"
And I click on "Delete" "link" in the "Test field" "table_row"
And I click on "Yes" "button" in the "Confirm" "dialogue"
Then I should not see "Test field"
And I log out
- @javascript
Scenario: A checkbox checked by default must be shown on listing but allow uncheck that will keep showing
Given the following "users" exist:
| username | firstname | lastname | email |
@@ -66,7 +63,7 @@ Feature: Managers can manage course custom fields checkbox
| Name | Test field |
| Short name | testfield |
| Checked by default | Yes |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Checkbox" "dialogue"
And I log out
And I log in as "teacher1"
And I am on site homepage
diff --git a/customfield/field/checkbox/tests/plugin_test.php b/customfield/field/checkbox/tests/plugin_test.php
index 9a64267af10a2..94ca651486120 100644
--- a/customfield/field/checkbox/tests/plugin_test.php
+++ b/customfield/field/checkbox/tests/plugin_test.php
@@ -103,21 +103,24 @@ public function test_initialise() {
* Create a configuration form and submit it with the same values as in the field
*/
public function test_config_form() {
+ $this->setAdminUser();
$submitdata = (array)$this->cfields[1]->to_record();
$submitdata['configdata'] = $this->cfields[1]->get('configdata');
- \core_customfield\field_config_form::mock_submit($submitdata, []);
- $handler = $this->cfcat->get_handler();
- $form = $handler->get_field_config_form($this->cfields[1]);
+ $submitdata = \core_customfield\field_config_form::mock_ajax_submit($submitdata);
+ $form = new \core_customfield\field_config_form(null, null, 'post', '', null, true,
+ $submitdata, true);
+ $form->set_data_for_dynamic_submission();
$this->assertTrue($form->is_validated());
- $data = $form->get_data();
- $handler->save_field_configuration($this->cfields[1], $data);
+ $form->process_dynamic_submission();
// Try submitting with 'unique values' checked.
$submitdata['configdata']['uniquevalues'] = 1;
- \core_customfield\field_config_form::mock_submit($submitdata, []);
- $handler = $this->cfcat->get_handler();
- $form = $handler->get_field_config_form($this->cfields[1]);
+
+ $submitdata = \core_customfield\field_config_form::mock_ajax_submit($submitdata);
+ $form = new \core_customfield\field_config_form(null, null, 'post', '', null, true,
+ $submitdata, true);
+ $form->set_data_for_dynamic_submission();
$this->assertFalse($form->is_validated());
}
diff --git a/customfield/field/date/tests/behat/field.feature b/customfield/field/date/tests/behat/field.feature
index f0bcbf378dfc3..822deb286bde6 100644
--- a/customfield/field/date/tests/behat/field.feature
+++ b/customfield/field/date/tests/behat/field.feature
@@ -1,4 +1,4 @@
-@customfield @customfield_date
+@customfield @customfield_date @javascript
Feature: Managers can manage course custom fields date
In order to have additional data on the course
As a manager
@@ -17,7 +17,7 @@ Feature: Managers can manage course custom fields date
And I set the following fields to these values:
| Name | Test field |
| Short name | testfield |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Date and time" "dialogue"
Then I should see "Test field"
And I log out
@@ -27,28 +27,26 @@ Feature: Managers can manage course custom fields date
And I set the following fields to these values:
| Name | Test field |
| Short name | testfield |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Date and time" "dialogue"
And I click on "[data-role='editfield']" "css_element"
And I set the following fields to these values:
| Name | Edited field |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Updating Test field" "dialogue"
Then I should see "Edited field"
And I log out
- @javascript
Scenario: Delete a custom course date field
When I click on "Add a new custom field" "link"
And I click on "Date and time" "link"
And I set the following fields to these values:
| Name | Test field |
| Short name | testfield |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Date and time" "dialogue"
And I click on "[data-role='deletefield']" "css_element"
And I click on "Yes" "button" in the "Confirm" "dialogue"
Then I should not see "Test field"
And I log out
- @javascript
Scenario: A date field makerd to include time must show those fields on course form
Given the following "users" exist:
| username | firstname | lastname | email |
@@ -65,7 +63,7 @@ Feature: Managers can manage course custom fields date
| Name | Test field |
| Short name | testfield |
| Include time | 1 |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Date and time" "dialogue"
And I log out
Then I log in as "teacher1"
When I am on site homepage
@@ -76,7 +74,6 @@ Feature: Managers can manage course custom fields date
Then "#id_customfield_testfield_minute" "css_element" should be visible
And I log out
- @javascript
Scenario: A date field makerd to not include time must not show those fields on course form
Given the following "users" exist:
| username | firstname | lastname | email |
@@ -93,7 +90,7 @@ Feature: Managers can manage course custom fields date
| Name | Test field |
| Short name | testfield |
| Include time | |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Date and time" "dialogue"
And I log out
Then I log in as "teacher1"
When I am on site homepage
diff --git a/customfield/field/date/tests/plugin_test.php b/customfield/field/date/tests/plugin_test.php
index 4d52f3bafaf28..039cf5e3a122e 100644
--- a/customfield/field/date/tests/plugin_test.php
+++ b/customfield/field/date/tests/plugin_test.php
@@ -100,15 +100,16 @@ public function test_initialise() {
* Create a configuration form and submit it with the same values as in the field
*/
public function test_config_form() {
+ $this->setAdminUser();
$submitdata = (array)$this->cfields[1]->to_record();
$submitdata['configdata'] = $this->cfields[1]->get('configdata');
- \core_customfield\field_config_form::mock_submit($submitdata, []);
- $handler = $this->cfcat->get_handler();
- $form = $handler->get_field_config_form($this->cfields[1]);
+ $submitdata = \core_customfield\field_config_form::mock_ajax_submit($submitdata);
+ $form = new \core_customfield\field_config_form(null, null, 'post', '', null, true,
+ $submitdata, true);
+ $form->set_data_for_dynamic_submission();
$this->assertTrue($form->is_validated());
- $data = $form->get_data();
- $handler->save_field_configuration($this->cfields[1], $data);
+ $form->process_dynamic_submission();
}
/**
diff --git a/customfield/field/select/tests/behat/field.feature b/customfield/field/select/tests/behat/field.feature
index 46413653ffa6b..9adb84ebc9d4b 100644
--- a/customfield/field/select/tests/behat/field.feature
+++ b/customfield/field/select/tests/behat/field.feature
@@ -1,4 +1,4 @@
-@customfield @customfield_select
+@customfield @customfield_select @javascript
Feature: Managers can manage course custom fields select
In order to have additional data on the course
As a manager
@@ -22,7 +22,7 @@ Feature: Managers can manage course custom fields select
a
b
"""
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Dropdown menu" "dialogue"
Then I should see "Test field"
And I log out
@@ -37,16 +37,15 @@ Feature: Managers can manage course custom fields select
a
b
"""
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Dropdown menu" "dialogue"
And I click on "Edit" "link" in the "Test field" "table_row"
And I set the following fields to these values:
| Name | Edited field |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Updating Test field" "dialogue"
Then I should see "Edited field"
And I should not see "Test field"
And I log out
- @javascript
Scenario: Delete a custom course select field
When I click on "Add a new custom field" "link"
And I click on "Dropdown menu" "link"
@@ -58,7 +57,7 @@ Feature: Managers can manage course custom fields select
a
b
"""
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Dropdown menu" "dialogue"
And I click on "Delete" "link" in the "Test field" "table_row"
And I click on "Yes" "button" in the "Confirm" "dialogue"
Then I should not see "Test field"
@@ -70,7 +69,7 @@ Feature: Managers can manage course custom fields select
And I set the following fields to these values:
| Name | Test field |
| Short name | testfield |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Dropdown menu" "dialogue"
And I should see "Please provide at least two options, with each on a new line." in the "Menu options (one per line)" "form_row"
And I set the field "Menu options (one per line)" to multiline:
"""
@@ -78,9 +77,9 @@ Feature: Managers can manage course custom fields select
b
"""
And I set the field "Default value" to "c"
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Dropdown menu" "dialogue"
And I should see "The default value must be one of the options from the list above" in the "Default value" "form_row"
And I set the field "Default value" to "b"
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Dropdown menu" "dialogue"
And "testfield" "text" should exist in the "Test field" "table_row"
And I log out
diff --git a/customfield/field/select/tests/plugin_test.php b/customfield/field/select/tests/plugin_test.php
index 937c2b86d1580..4cc5eefbcfbb1 100644
--- a/customfield/field/select/tests/plugin_test.php
+++ b/customfield/field/select/tests/plugin_test.php
@@ -104,15 +104,16 @@ public function test_initialise() {
* Create a configuration form and submit it with the same values as in the field
*/
public function test_config_form() {
+ $this->setAdminUser();
$submitdata = (array)$this->cfields[1]->to_record();
$submitdata['configdata'] = $this->cfields[1]->get('configdata');
- \core_customfield\field_config_form::mock_submit($submitdata, []);
- $handler = $this->cfcat->get_handler();
- $form = $handler->get_field_config_form($this->cfields[1]);
+ $submitdata = \core_customfield\field_config_form::mock_ajax_submit($submitdata);
+ $form = new \core_customfield\field_config_form(null, null, 'post', '', null, true,
+ $submitdata, true);
+ $form->set_data_for_dynamic_submission();
$this->assertTrue($form->is_validated());
- $data = $form->get_data();
- $handler->save_field_configuration($this->cfields[1], $data);
+ $form->process_dynamic_submission();
}
/**
diff --git a/customfield/field/text/tests/behat/field.feature b/customfield/field/text/tests/behat/field.feature
index da4ad414b9347..5939cf0986e62 100644
--- a/customfield/field/text/tests/behat/field.feature
+++ b/customfield/field/text/tests/behat/field.feature
@@ -1,4 +1,4 @@
-@customfield @customfield_text
+@customfield @customfield_text @javascript
Feature: Managers can manage course custom fields text
In order to have additional data on the course
As a manager
@@ -17,7 +17,7 @@ Feature: Managers can manage course custom fields text
And I set the following fields to these values:
| Name | Test field |
| Short name | testfield |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Short text" "dialogue"
Then I should see "Test field"
And I log out
@@ -27,24 +27,23 @@ Feature: Managers can manage course custom fields text
And I set the following fields to these values:
| Name | Test field |
| Short name | testfield |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Short text" "dialogue"
And I click on "Edit" "link" in the "Test field" "table_row"
And I set the following fields to these values:
| Name | Edited field |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Updating Test field" "dialogue"
Then I should see "Edited field"
And I navigate to "Reports > Logs" in site administration
And I press "Get these logs"
And I log out
- @javascript
Scenario: Delete a custom course text field
When I click on "Add a new custom field" "link"
And I click on "Short text" "link"
And I set the following fields to these values:
| Name | Test field |
| Short name | testfield |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Short text" "dialogue"
And I click on "Delete" "link" in the "Test field" "table_row"
And I click on "Yes" "button" in the "Confirm" "dialogue"
And I wait until the page is ready
@@ -70,7 +69,7 @@ Feature: Managers can manage course custom fields text
| Short name | testfield |
| Visible to | Everyone |
| Link | https://www.moodle.org/$$ |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Short text" "dialogue"
And I log out
Then I log in as "teacher1"
And I am on "Course 1" course homepage
@@ -99,7 +98,7 @@ Feature: Managers can manage course custom fields text
| Name | Test field |
| Short name | testfield |
| Maximum number of characters | 3 |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Short text" "dialogue"
And I log out
Then I log in as "teacher1"
And I am on "Course 1" course homepage
@@ -126,7 +125,7 @@ Feature: Managers can manage course custom fields text
| Name | Test field |
| Short name | testfield |
| Default value | testdefault |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Short text" "dialogue"
And I log out
Then I log in as "teacher1"
When I am on site homepage
diff --git a/customfield/field/text/tests/plugin_test.php b/customfield/field/text/tests/plugin_test.php
index b52d5a0685aa4..d98d846d7ce40 100644
--- a/customfield/field/text/tests/plugin_test.php
+++ b/customfield/field/text/tests/plugin_test.php
@@ -109,15 +109,16 @@ public function test_initialise() {
* Create a configuration form and submit it with the same values as in the field
*/
public function test_config_form() {
+ $this->setAdminUser();
$submitdata = (array)$this->cfields[1]->to_record();
$submitdata['configdata'] = $this->cfields[1]->get('configdata');
- \core_customfield\field_config_form::mock_submit($submitdata, []);
- $handler = $this->cfcat->get_handler();
- $form = $handler->get_field_config_form($this->cfields[1]);
+ $submitdata = \core_customfield\field_config_form::mock_ajax_submit($submitdata);
+ $form = new \core_customfield\field_config_form(null, null, 'post', '', null, true,
+ $submitdata, true);
+ $form->set_data_for_dynamic_submission();
$this->assertTrue($form->is_validated());
- $data = $form->get_data();
- $handler->save_field_configuration($this->cfields[1], $data);
+ $form->process_dynamic_submission();
}
/**
diff --git a/customfield/field/textarea/tests/behat/default_value.feature b/customfield/field/textarea/tests/behat/default_value.feature
index 44004d008146c..42bea1acef2e0 100644
--- a/customfield/field/textarea/tests/behat/default_value.feature
+++ b/customfield/field/textarea/tests/behat/default_value.feature
@@ -35,14 +35,14 @@ Feature: Default value for the textarea custom field can contain images
| Default value | v |
# Embed the image into Default value.
And I select the text in the "Default value" Atto editor
- And I click on "Insert or edit image" "button" in the "//*[@data-fieldtype='editor']/*[descendant::*[@id='id_configdata_defaultvalue_editoreditable']]" "xpath_element"
+ And I click on "Insert or edit image" "button" in the "Default value" "form_row"
And I click on "Browse repositories..." "button"
And I click on "Private files" "link" in the ".fp-repo-area" "css_element"
And I click on "gd-logo.png" "link"
And I click on "Select this file" "button"
And I set the field "Describe this image for someone who cannot see it" to "Example"
And I click on "Save image" "button"
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Text area" "dialogue"
And I log out
Scenario: For the courses that existed before the custom field was created the default value is displayed
@@ -55,7 +55,7 @@ Feature: Default value for the textarea custom field can contain images
And I am on "Course 1" course homepage
And I navigate to "Edit settings" in current page administration
And I expand all fieldsets
- Then "//*[@id='id_customfield_testfield_editoreditable']//img[contains(@src, 'draftfile.php') and contains(@src, '/gd-logo.png') and @alt='Example']" "xpath_element" should exist
+ Then "//img[contains(@src, 'draftfile.php') and contains(@src, '/gd-logo.png') and @alt='Example']" "xpath_element" should exist in the "Test field" "form_row"
# Save the course without changing the default value.
And I press "Save and display"
And I log out
@@ -72,7 +72,7 @@ Feature: Default value for the textarea custom field can contain images
| Course full name | Course 2 |
| Course short name | C2 |
And I expand all fieldsets
- Then "//*[@id='id_customfield_testfield_editoreditable']//img[contains(@src, 'draftfile.php') and contains(@src, '/gd-logo.png') and @alt='Example']" "xpath_element" should exist
+ Then "//img[contains(@src, 'draftfile.php') and contains(@src, '/gd-logo.png') and @alt='Example']" "xpath_element" should exist in the "Test field" "form_row"
And I press "Save and display"
And I log out
# Now the same image is displayed as "value" and not as "defaultvalue".
diff --git a/customfield/field/textarea/tests/behat/field.feature b/customfield/field/textarea/tests/behat/field.feature
index 70936012c0aee..b0416b5e6802c 100644
--- a/customfield/field/textarea/tests/behat/field.feature
+++ b/customfield/field/textarea/tests/behat/field.feature
@@ -1,4 +1,4 @@
-@customfield @customfield_textarea
+@customfield @customfield_textarea @javascript
Feature: Managers can manage course custom fields textarea
In order to have additional data on the course
As a manager
@@ -17,7 +17,7 @@ Feature: Managers can manage course custom fields textarea
And I set the following fields to these values:
| Name | Test field |
| Short name | testfield |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Text area" "dialogue"
Then I should see "Test field"
And I log out
@@ -27,23 +27,22 @@ Feature: Managers can manage course custom fields textarea
And I set the following fields to these values:
| Name | Test field |
| Short name | testfield |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Text area" "dialogue"
And I click on "Edit" "link" in the "Test field" "table_row"
And I set the following fields to these values:
| Name | Edited field |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Updating Test field" "dialogue"
Then I should see "Edited field"
And I should not see "Test field"
And I log out
- @javascript
Scenario: Delete a custom course textarea field
When I click on "Add a new custom field" "link"
And I click on "Text area" "link"
And I set the following fields to these values:
| Name | Test field |
| Short name | testfield |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Text area" "dialogue"
And I click on "Delete" "link" in the "Test field" "table_row"
And I click on "Yes" "button" in the "Confirm" "dialogue"
Then I should not see "Test field"
diff --git a/customfield/field/textarea/tests/plugin_test.php b/customfield/field/textarea/tests/plugin_test.php
index 9c48ad6e24e2a..eefbfb10fe215 100644
--- a/customfield/field/textarea/tests/plugin_test.php
+++ b/customfield/field/textarea/tests/plugin_test.php
@@ -105,15 +105,16 @@ public function test_initialise() {
* Create a configuration form and submit it with the same values as in the field
*/
public function test_config_form() {
+ $this->setAdminUser();
$submitdata = (array)$this->cfields[3]->to_record();
$submitdata['configdata'] = $this->cfields[3]->get('configdata');
- \core_customfield\field_config_form::mock_submit($submitdata, []);
- $handler = $this->cfcat->get_handler();
- $form = $handler->get_field_config_form($this->cfields[3]);
+ $submitdata = \core_customfield\field_config_form::mock_ajax_submit($submitdata);
+ $form = new \core_customfield\field_config_form(null, null, 'post', '', null, true,
+ $submitdata, true);
+ $form->set_data_for_dynamic_submission();
$this->assertTrue($form->is_validated());
- $data = $form->get_data();
- $handler->save_field_configuration($this->cfields[3], $data);
+ $form->process_dynamic_submission();
}
/**
diff --git a/customfield/templates/list.mustache b/customfield/templates/list.mustache
index f91aa2d1f2082..2de5bd8ec3603 100644
--- a/customfield/templates/list.mustache
+++ b/customfield/templates/list.mustache
@@ -106,7 +106,7 @@
{{{shortname}}} |
{{{type}}} |
- {{#pix}}
+ {{#pix}}
t/edit, core, {{#str}} edit, moodle {{/str}} {{/pix}}
{{#pix}}
t/delete, core, {{#str}} delete, moodle {{/str}} {{/pix}}
diff --git a/customfield/tests/behat/edit_fields_settings.feature b/customfield/tests/behat/edit_fields_settings.feature
index cf9cf34f7e3a4..bebbdb90468aa 100644
--- a/customfield/tests/behat/edit_fields_settings.feature
+++ b/customfield/tests/behat/edit_fields_settings.feature
@@ -1,4 +1,4 @@
-@core @core_course @core_customfield
+@core @core_course @core_customfield @javascript
Feature: Teachers can edit course custom fields
In order to have additional data on the course
As a teacher
@@ -80,14 +80,14 @@ Feature: Teachers can edit course custom fields
And I navigate to "Courses > Course custom fields" in site administration
And I click on "Edit" "link" in the "Field 1" "table_row"
And I select the text in the "Description" Atto editor
- And I click on "Insert or edit image" "button" in the "//*[@data-fieldtype='editor']/*[descendant::*[@id='id_description_editoreditable']]" "xpath_element"
+ And I click on "Insert or edit image" "button" in the "Description" "form_row"
And I click on "Browse repositories..." "button"
And I click on "Private files" "link" in the ".fp-repo-area" "css_element"
And I click on "gd-logo.png" "link"
And I click on "Select this file" "button"
And I set the field "Describe this image for someone who cannot see it" to "Example"
And I click on "Save image" "button"
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Updating Field 1" "dialogue"
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage
@@ -104,12 +104,13 @@ Feature: Teachers can edit course custom fields
And I click on "Short text" "link"
And I set the following fields to these values:
| Name | Test field |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Short text" "dialogue"
Then I should see "You must supply a value here" in the "Short name" "form_row"
And I set the field "Short name" to "short name"
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Short text" "dialogue"
And I should see "The short name can only contain alphanumeric lowercase characters and underscores (_)." in the "Short name" "form_row"
And I set the field "Short name" to "f1"
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Short text" "dialogue"
And I should see "Short name already exists" in the "Short name" "form_row"
+ And I click on "Cancel" "button" in the "Adding a new Short text" "dialogue"
And I log out
diff --git a/customfield/tests/behat/required_field.feature b/customfield/tests/behat/required_field.feature
index 56c0f23581a4e..fa3f952767eda 100644
--- a/customfield/tests/behat/required_field.feature
+++ b/customfield/tests/behat/required_field.feature
@@ -1,4 +1,4 @@
-@core @core_course @core_customfield
+@core @core_course @core_customfield @javascript
Feature: Requiredness The course custom fields can be mandatory or not
In order to make users required to fill a custom field
As a manager
@@ -27,7 +27,7 @@ Feature: Requiredness The course custom fields can be mandatory or not
| Name | Test field |
| Short name | testfield |
| Required | Yes |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Short text" "dialogue"
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage
@@ -48,7 +48,7 @@ Feature: Requiredness The course custom fields can be mandatory or not
| Name | Test field |
| Short name | testfield |
| Required | No |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Short text" "dialogue"
And I log out
And I log in as "teacher1"
And I am on "Course 1" course homepage
diff --git a/customfield/tests/behat/unique_field.feature b/customfield/tests/behat/unique_field.feature
index c48acae3b3eba..bb7e983fdf697 100644
--- a/customfield/tests/behat/unique_field.feature
+++ b/customfield/tests/behat/unique_field.feature
@@ -1,4 +1,4 @@
-@core @core_course @core_customfield
+@core @core_course @core_customfield @javascript
Feature: Uniqueness The course custom fields can be mandatory or not
In order to make users required to fill a custom field
As a manager
@@ -27,7 +27,7 @@ Feature: Uniqueness The course custom fields can be mandatory or not
| Name | Test field |
| Short name | testfield |
| Unique data | Yes |
- And I press "Save changes"
+ And I click on "Save changes" "button" in the "Adding a new Short text" "dialogue"
And I log out
Scenario: A course custom field with unique data must not allow same data in same field in different courses
diff --git a/customfield/upgrade.txt b/customfield/upgrade.txt
new file mode 100644
index 0000000000000..d133fbf4bff00
--- /dev/null
+++ b/customfield/upgrade.txt
@@ -0,0 +1,8 @@
+This files describes API changes in /customfield/*,
+Information provided here is intended especially for developers.
+
+=== 3.11 ===
+* Methods \core_customfield\handler::get_field_config_form() and \core_customfield\handler::setup_edit_page() are no
+ longer used. Components that define custom fields areas do not need to implement them. Field edit form opens in
+ the modal now.
+
|