Merge branch 'MDL-78649-master' of https://github.com/meirzamoodle/moodle

This commit is contained in:
Andrew Nicols
2023-09-21 22:25:14 +08:00
4 changed files with 65 additions and 15 deletions
+5 -7
View File
@@ -229,13 +229,11 @@ class api {
/**
* Set the form definitions for the plugins.
*
* @param \MoodleQuickForm $mform
* @return void
* @param \MoodleQuickForm $mform The moodle form
* @param string $provider The provider name
*/
public function form_definition_for_provider(\MoodleQuickForm $mform): void {
$provider = $mform->getElementValue('selectedcommunication');
if ($provider[0] !== processor::PROVIDER_NONE) {
public function form_definition_for_provider(\MoodleQuickForm $mform, string $provider = processor::PROVIDER_NONE): void {
if ($provider !== processor::PROVIDER_NONE) {
// Room name for the communication provider.
$mform->insertElementBefore(
$mform->createElement(
@@ -247,7 +245,7 @@ class api {
$mform->addHelpButton('communicationroomname', 'communicationroomname', 'communication');
$mform->setType('communicationroomname', PARAM_TEXT);
processor::set_proider_form_definition($provider[0], $mform);
processor::set_provider_specific_form_definition($provider, $mform);
}
}
+48 -5
View File
@@ -38,6 +38,34 @@ class configure_form extends \moodleform {
*/
protected $communication;
/**
* Class constructor
*
* @param \stdClass $course Course object
* @param int|null $instanceid Instance ID
* @param string|null $instancetype Instance type
* @param string|null $component Component name
* @param string|null $selectedcommunication Selected communication service (provider)
*/
public function __construct(
\stdClass $course,
?int $instanceid = null,
?string $instancetype = null,
?string $component = null,
?string $selectedcommunication = null,
) {
parent::__construct(
null,
[
'instance' => $course,
'instanceid' => $instanceid,
'instancetype' => $instancetype,
'component' => $component,
'selectedcommunication' => $selectedcommunication,
],
);
}
/**
* Defines the form fields.
*/
@@ -57,6 +85,8 @@ class configure_form extends \moodleform {
$this->communication->form_definition($mform);
$this->communication->set_data($instance);
$this->set_form_definition_for_provider();
// Form buttons.
$buttonarray = [];
$buttonarray[] = $mform->createElement('submit', 'saveandreturn', get_string('savechanges'));
@@ -77,11 +107,24 @@ class configure_form extends \moodleform {
}
/**
* Fill in the communication page data depending on provider selected.
* Defines the requested/current provider
*
* Get the selected communication service (provider),
* and then use it to show the provider form fields.
*/
public function definition_after_data() {
$mform = $this->_form;
// Add communication plugins to the form with respect to the provider.
$this->communication->form_definition_for_provider($mform);
private function set_form_definition_for_provider(): void {
$instance = $this->_customdata['instance'];
if ($selectedcommunication = $this->_customdata['selectedcommunication']) {
// First is to check whether the selected communication was selected from the form.
$provider = $selectedcommunication;
} else if (isset($instance->selectedcommunication)) {
// If the form is not yet submitted, get the value from the DB.
$provider = $instance->selectedcommunication;
} else {
// Otherwise, set to PROVIDER_NONE.
$provider = \core_communication\processor::PROVIDER_NONE;
}
$this->communication->form_definition_for_provider($this->_form, $provider);
}
}
+2 -2
View File
@@ -462,12 +462,12 @@ class processor {
}
/**
* Get communication provider for form feature.
* Set provider specific form definition.
*
* @param string $provider The provider name
* @param \MoodleQuickForm $mform The moodle form
*/
public static function set_proider_form_definition(string $provider, \MoodleQuickForm $mform): void {
public static function set_provider_specific_form_definition(string $provider, \MoodleQuickForm $mform): void {
$providerclass = "{$provider}\\communication_feature";
$providerclass::set_form_definition($mform);
}
+10 -1
View File
@@ -30,6 +30,7 @@ require_login();
$instanceid = required_param('instanceid', PARAM_INT);
$instancetype = required_param('instancetype', PARAM_TEXT);
$component = required_param('component', PARAM_COMPONENT);
$selectedcommunication = optional_param('selectedcommunication', null, PARAM_PLUGIN);
$instanceinfo = [
'instanceid' => $instanceid,
@@ -66,8 +67,16 @@ $PAGE->add_body_class('limitedwidth');
// Append the instance data before passing to form object.
$instanceinfo['instance'] = $instance;
// Get our form definitions.
$form = new \core_communication\form\configure_form(null, $instanceinfo);
$form = new \core_communication\form\configure_form(
course: $instanceinfo['instance'],
instanceid: $instanceinfo['instanceid'],
instancetype: $instanceinfo['instancetype'],
component: $instanceinfo['component'],
selectedcommunication: $selectedcommunication
);
if ($form->is_cancelled()) {