mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-78553 core_communication: Move settings to their own page
- Loading branch information
1 parent
5aea409
commit 317251a
Showing
21 changed files
with
383 additions
and
75 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Configure communication for a given instance - the form definition. | ||
* | ||
* @package core_communication | ||
* @copyright 2023 David Woloszyn <david.woloszyn@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace core_communication\form; | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
require_once($CFG->libdir.'/formslib.php'); | ||
|
||
/** | ||
* Defines the configure communication form. | ||
*/ | ||
class configure_form extends \moodleform { | ||
|
||
/** | ||
* @var \core_communication\api $communication The communication api object. | ||
*/ | ||
protected $communication; | ||
|
||
/** | ||
* Defines the form fields. | ||
*/ | ||
public function definition() { | ||
$mform = $this->_form; | ||
$instanceid = $this->_customdata['instanceid']; | ||
$instancetype = $this->_customdata['instancetype']; | ||
$component = $this->_customdata['component']; | ||
$instance = $this->_customdata['instance']; | ||
|
||
// Add communication plugins to the form. | ||
$this->communication = \core_communication\api::load_by_instance( | ||
$component, | ||
$instancetype, | ||
$instanceid | ||
); | ||
$this->communication->form_definition($mform); | ||
$this->communication->set_data($instance); | ||
|
||
// Form buttons. | ||
$buttonarray = []; | ||
$buttonarray[] = $mform->createElement('submit', 'saveandreturn', get_string('savechanges')); | ||
$buttonarray[] = $mform->createElement('cancel'); | ||
$mform->addGroup($buttonarray, 'buttonar', '', [' '], false); | ||
$mform->closeHeaderBefore('buttonar'); | ||
|
||
// Hidden elements. | ||
$mform->addElement('hidden', 'instanceid', $instanceid); | ||
$mform->setType('instanceid', PARAM_INT); | ||
$mform->addElement('hidden', 'instancetype', $instancetype); | ||
$mform->setType('instancetype', PARAM_TEXT); | ||
$mform->addElement('hidden', 'component', $component); | ||
$mform->setType('component', PARAM_TEXT); | ||
|
||
// Finally set the current form data. | ||
$this->set_data($instance); | ||
} | ||
|
||
/** | ||
* Fill in the communication page data depending on provider selected. | ||
*/ | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Configure communication for a given instance. | ||
* | ||
* @package core_communication | ||
* @copyright 2023 David Woloszyn <david.woloszyn@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
require_once('../config.php'); | ||
require_once('lib.php'); | ||
|
||
require_login(); | ||
|
||
$instanceid = required_param('instanceid', PARAM_INT); | ||
$instancetype = required_param('instancetype', PARAM_TEXT); | ||
$component = required_param('component', PARAM_COMPONENT); | ||
|
||
$instanceinfo = [ | ||
'instanceid' => $instanceid, | ||
'instancetype' => $instancetype, | ||
'component' => $component, | ||
]; | ||
|
||
// Requires communication to be enabled. | ||
if (!core_communication\api::is_available()) { | ||
throw new \moodle_exception('communicationdisabled', 'communication'); | ||
} | ||
|
||
// Attempt to load the communication instance with the provided params. | ||
$communication = \core_communication\api::load_by_instance($component, $instancetype, $instanceid); | ||
|
||
// No communication, no way this form can be used. | ||
if (!$communication) { | ||
throw new \moodle_exception('nocommunicationinstance', 'communication'); | ||
} | ||
|
||
// Set variables according to the component callback and use them on the page. | ||
list($instance, $context, $heading, $returnurl) = component_callback( | ||
$component, | ||
'get_communication_instance_data', | ||
[$instanceid] | ||
); | ||
|
||
// Set up the page. | ||
$PAGE->set_context($context); | ||
$PAGE->set_url('/communication/configure.php', $instanceinfo); | ||
$PAGE->set_title(get_string('communication', 'communication')); | ||
$PAGE->set_heading($heading); | ||
$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); | ||
|
||
if ($form->is_cancelled()) { | ||
|
||
redirect($returnurl); | ||
|
||
} else if ($data = $form->get_data()) { | ||
|
||
component_callback($component, 'update_communication_instance_data', [$data]); | ||
redirect($returnurl); | ||
} | ||
|
||
// Display the page contents. | ||
echo $OUTPUT->header(); | ||
echo $OUTPUT->heading(get_string('communication', 'communication'), 2); | ||
$form->display(); | ||
echo $OUTPUT->footer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
communication/tests/behat/communication_configuration.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
@communication | ||
Feature: Access the communication configuration page | ||
As an editing teacher | ||
See dynamic form fields based on selected provider | ||
|
||
Background: Set up teachers and course for the communication confifiguration page | ||
Given I enable communication experimental feature | ||
And the following "users" exist: | ||
| username | firstname | lastname | email | | ||
| teacher1 | Teacher | 1 | teacher1@example.com | | ||
| teacher2 | Teacher | 2 | teacher2@example.com | | ||
And the following "courses" exist: | ||
| fullname | shortname | category | selectedcommunication | | ||
| Test course | Test course | 0 | none | | ||
And the following "course enrolments" exist: | ||
| user | course | role | | ||
| teacher1 | Test course | editingteacher | | ||
| teacher2 | Test course | teacher | | ||
|
||
Scenario: A teacher with the correct capability can access the communication configuration page | ||
Given I am on the "Test course" "Course" page logged in as "teacher1" | ||
When I navigate to "Communication" in current page administration | ||
Then I should see "Communication" | ||
|
||
Scenario: A teacher without the correct capability cannot access the communication configuration page | ||
Given I am on the "Test course" "Course" page logged in as "teacher2" | ||
Then "Communication" "link" should not exist in current page administration | ||
|
||
Scenario: I cannot see the communication link when communication provider is disabled | ||
Given I disable communication experimental feature | ||
And I am on the "Test course" "Course" page logged in as "teacher1" | ||
Then "Communication" "link" should not exist in current page administration | ||
|
||
@javascript | ||
Scenario: The communication form fields toggle dynamically when valid provider is set | ||
Given I am on the "Test course" "Course" page logged in as "teacher1" | ||
When I navigate to "Communication" in current page administration | ||
And I set the following fields to these values: | ||
| selectedcommunication | communication_matrix | | ||
Then I should see "Room name" | ||
And I should see "Room topic" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.