Merge branch 'MDL-79762-master' of https://github.com/kabalin/moodle

This commit is contained in:
Paul Holden 2023-10-25 23:55:52 +01:00
commit 5036ebd7d1
No known key found for this signature in database
GPG Key ID: A81A96D6045F6164
4 changed files with 32 additions and 6 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -43,7 +43,6 @@ import ModalEvents from 'core/modal_events';
import Notification from 'core/notification';
import Pending from 'core/pending';
import {serialize} from './util';
import SaveCancelModal from 'core/modal_save_cancel';
export default class ModalForm {
@ -89,8 +88,9 @@ export default class ModalForm {
*
* @param {Object} config parameters for the form and modal dialogue:
* @paramy {String} config.formClass PHP class name that handles the form (should extend \core_form\modal )
* @paramy {Object} config.modalConfig modal config - title, type, etc.
* Default: {removeOnClose: true, type: ModalFactory.types.SAVE_CANCEL}
* @paramy {String} config.moduleName module name to use if different to core/modal_save_cancel (optional)
* @paramy {Object} config.modalConfig modal config - title, header, footer, etc.
* Default: {removeOnClose: true, large: true}
* @paramy {Object} config.args Arguments for the initial form rendering (for example, id of the edited entity)
* @paramy {String} config.saveButtonText the text to display on the Modal "Save" button (optional)
* @paramy {String} config.saveButtonClasses additional CSS classes for the Modal "Save" button
@ -108,6 +108,28 @@ export default class ModalForm {
this.futureListeners = [];
}
/**
* Loads the modal module and creates an instance
*
* @returns {Promise}
*/
getModalModule() {
if (!this.config.moduleName && this.config.modalConfig.type && this.config.modalConfig.type !== 'SAVE_CANCEL') {
// Legacy loader for plugins that were not updated with Moodle 4.3 changes.
window.console.warn(
'Passing config.modalConfig.type to ModalForm has been deprecated since Moodle 4.3. ' +
'Please pass config.modalName instead with the full module name.',
);
return import('core/modal_factory')
.then((ModalFactory) => ModalFactory.create(this.config.modalConfig));
} else {
// New loader for Moodle 4.3 and above.
const moduleName = this.config.moduleName ?? 'core/modal_save_cancel';
return import(moduleName)
.then((module) => module.create(this.config.modalConfig));
}
}
/**
* Initialise the modal and shows it
*
@ -116,7 +138,7 @@ export default class ModalForm {
show() {
const pendingPromise = new Pending('core_form/modalform:init');
return SaveCancelModal.create(this.config.modalConfig)
return this.getModalModule()
.then((modal) => {
this.modal = modal;

View File

@ -1,6 +1,10 @@
This files describes API changes in core libraries and APIs,
information provided here is intended especially for developers.
=== 4.3.1 ===
* Added modalform config object `moduleName` param that can be used to define alternative modal type for the modalform. By default 'core/modal_save_cancel' is used.
=== 4.3 ===
* Unnecessary parameters of admin_apply_default_settings() function were removed; upgrade script lists