$returnurl = "$CFG->wwwroot/$CFG->admin/settings.php?section=manageauths";
+debugging("Use of config.html files in authentication plugins have been depreciated. " .
+ " Please migrate your plugin to use the admin settings API", DEBUG_DEVELOPER);
+
// save configuration changes
if ($frm = data_submitted() and confirm_sesskey()) {
/// Functions /////////////////////////////////////////////////////////////////
-// Good enough for most auth plugins
-// but some may want a custom one if they are offering
-// other options
-// Note: lockconfig_ fields have special handling.
+
+/**
+ * auth field locking
+ * Good enough for most auth plugins
+ * but some may want a custom one if they are offering
+ * other options
+ * Note: lockconfig_ fields have special handling.
+ *
+ * @param string $auth authentication plugin shortname
+ * @param array $user_fields user profile fields
+ * @param string $helptext help text to be displayed at top of form
+ * @param boolean $retrieveopts Map fields or lock only.
+ * @param boolean $updateopts Allow remote updates
+ * @param array $customfields list of custom profile fields
+ * @deprecated since Moodle 3.3
+ */
function print_auth_lock_options($auth, $user_fields, $helptext, $retrieveopts, $updateopts, $customfields = array()) {
global $DB, $OUTPUT;
+ debugging("The function 'print_auth_lock_options' has been depreciated, " .
+ "Please migrate your code to use the admin settings API and use the function 'display_auth_lock_options' instead. ",
+ DEBUG_DEVELOPER);
+
echo '<tr><td colspan="3">';
if ($retrieveopts) {
echo $OUTPUT->heading(get_string('auth_data_mapping', 'auth'));
// remove from enabled list
$key = array_search($editor, $active_editors);
unset($active_editors[$key]);
+ add_to_config_log('editor_visibility', '1', '0', $editor);
break;
case 'enable':
if (!in_array($editor, $active_editors)) {
$active_editors[] = $editor;
$active_editors = array_unique($active_editors);
+ add_to_config_log('editor_visibility', '0', '1', $editor);
}
break;
$fsave = $active_editors[$key];
$active_editors[$key] = $active_editors[$key + 1];
$active_editors[$key + 1] = $fsave;
+ add_to_config_log('editor_position', $key, $key + 1, $editor);
}
}
break;
$fsave = $active_editors[$key];
$active_editors[$key] = $active_editors[$key - 1];
$active_editors[$key - 1] = $fsave;
+ add_to_config_log('editor_position', $key, $key - 1, $editor);
}
}
break;
require_once(__DIR__ . '/../config.php');
+$error = optional_param('error', '', PARAM_RAW);
+if ($error) {
+ $message = optional_param('error_description', '', PARAM_RAW);
+ if ($message) {
+ print_error($message);
+ } else {
+ print_error($error);
+ }
+ die();
+}
+
// The authorization code generated by the authorization server.
$code = required_param('code', PARAM_RAW);
// The state parameter we've given (used in moodle as a redirect url).
| fullname | shortname |
| Course fullname | C_shortname |
And I log in as "admin"
- And I am on site homepage
@javascript
Scenario: Override a permission
- Given I follow "Course fullname"
+ Given I am on "Course fullname" course homepage
And I navigate to "Users > Permissions" in current page administration
And I select "Manager (0)" from the "roleid" singleselect
And I click on "Prohibit" "radio" in the "View added and updated modules in recent activity block" "table_row"
// Completion tracking.
$temp->add(new admin_setting_heading('progress', new lang_string('completion','completion'), ''));
$temp->add(new admin_setting_configselect('moodlecourse/enablecompletion', new lang_string('completion', 'completion'),
- new lang_string('enablecompletion_help', 'completion'), 0, array(0 => new lang_string('no'), 1 => new lang_string('yes'))));
+ new lang_string('enablecompletion_help', 'completion'), 1, array(0 => new lang_string('no'), 1 => new lang_string('yes'))));
// Groups.
$temp->add(new admin_setting_heading('groups', new lang_string('groups', 'group'), ''));
# OK, toggling works. Set the grade one to Hide and we'll go see if it actually worked.
And I click on "Hide" "icon" in the "Restriction by grade" "table_row"
- And I am on site homepage
- And I follow "Course 1"
- And I turn editing mode on
+ And I am on "Course 1" course homepage with editing mode on
And I add a "Page" to section "1"
And I expand all fieldsets
And I click on "Add restriction..." "button"
| Grouping 1 | C1 | GG1 |
| Grouping 2 | C1 | GG2 |
When I log in as "admin"
- And I am on site homepage
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I navigate to "Users > Groups" in current page administration
Then I should see "Group 1"
And I should see "Group 2"
| mod/forum:editanypost | Allow | student | Course | C1 |
| mod/forum:replynews | Prevent | editingteacher | Course | C1 |
When I log in as "admin"
- And I am on site homepage
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I navigate to "Users > Permissions" in current page administration
And I set the field "Advanced role override" to "Student (1)"
Then "mod/forum:editanypost" capability has "Allow" permission
| user | course | role |
| student1 | C1 | student |
When I log in as "student1"
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
Then I should see "Topic 1"
Scenario: Add role assigns
Then "Edit settings" "link" should exist in current page administration
And I log out
And I log in as "user2"
- And I am on site homepage
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And "Turn editing on" "link" should exist in current page administration
And I log out
And I log in as "user3"
- And I am on site homepage
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And "Turn editing on" "link" should exist in current page administration
And I log out
And I log in as "user4"
- And I am on site homepage
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And "Turn editing on" "link" should exist in current page administration
And I log out
And I log in as "user5"
And I should see "You are logged in as"
- And I am on site homepage
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I should see "You can not enrol yourself in this course."
Scenario: Add modules
| activity | name | intro | course | idnumber | grade |
| assign | Test assignment name with scale | Test assignment description | C1 | assign1 | Test Scale 1 |
When I log in as "admin"
- And I am on site homepage
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
Then I should see "Test assignment name"
# Assignment 2.2 module type is disabled by default
# And I should see "Test assignment22 name"
| grouping | group |
| GG1 | G1 |
When I log in as "admin"
- And I am on site homepage
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I navigate to "Users > Groups" in current page administration
Then the "groups" select box should contain "Group 1 (1)"
And the "groups" select box should contain "Group 2 (1)"
| Grade sub category 2 | C1 | Grade category 1 |
When I log in as "admin"
And I am on course index
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I navigate to "View > Grader report" in the course gradebook
Then I should see "Grade category 1"
And I should see "Grade sub category 2"
| Test Grade Item 2 | C1 | Grade category 1 |
| Test Grade Item 3 | C1 | Grade sub category 2 |
When I log in as "admin"
- And I am on site homepage
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I navigate to "Setup > Gradebook setup" in the course gradebook
Then I should see "Test Grade Item 1"
And I follow "Edit Test Grade Item 1"
| name | scale |
| Test Scale 1 | Disappointing, Good, Very good, Excellent |
When I log in as "admin"
- And I am on site homepage
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I navigate to "Scales" in the course gradebook
Then I should see "Test Scale 1"
And I should see "Disappointing, Good, Very good, Excellent"
And the following config values are set as admin:
| enableoutcomes | 1 |
When I log in as "admin"
- And I am on site homepage
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I follow "Outcomes"
Then I should see "Grade outcome 1" in the "#addoutcomes" "css_element"
And I should see "Grade outcome 2" in the "#removeoutcomes" "css_element"
And the following config values are set as admin:
| enableoutcomes | 1 |
When I log in as "admin"
- And I am on site homepage
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I navigate to "Setup > Gradebook setup" in the course gradebook
Then I should see "Test Outcome Grade Item 1"
And I follow "Edit Test Outcome Grade Item 1"
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| online_users | Course | C1 | course-view-* | site-pre |
When I log in as "admin"
- And I am on site homepage
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
Then I should see "Online users"
| user | course | role |
| teacher1 | C1 | editingteacher |
And I log in as "teacher1"
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I follow "Test assignment name"
And I should see "##yesterday##l, j F Y##"
And I log out
Scenario: Course capabilities overrides
Given I log in as "teacher1"
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I navigate to "Users > Permissions" in current page administration
And I override the system permissions of "Student" role with:
| mod/forum:deleteanypost | Prohibit |
Scenario: Module capabilities overrides
Given I log in as "teacher1"
- And I follow "Course 1"
- And I turn editing mode on
+ And I am on "Course 1" course homepage with editing mode on
And I add a "Forum" to section "1" and I fill the form with:
| Forum name | I'm the name |
| Description | I'm the introduction |
| activity | course | idnumber | name | intro | firstpagetitle | wikimode | visible |
| wiki | C1 | wiki1 | Test this one | Test this one | Test this one | collaborative | 0 |
And I log in as "admin"
- And I am on site homepage
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I navigate to "Reset" node in "Course administration"
# Select (multi-select) - Checking "the select box should contain".
And I expand all fieldsets
And the "Unenrol users" select box should not contain "President"
And the "Unenrol users" select box should not contain "Baker"
And the "Unenrol users" select box should not contain "President, Baker"
- And I am on site homepage
- And I follow "Course 1"
- And I turn editing mode on
+ And I am on "Course 1" course homepage with editing mode on
And I follow "Test this one"
And I press "Create page"
# Text (textarea & editor) & Select (multi-select) - Checking "I set the following fields to these values".
| Default format | HTML |
| Force format | 1 |
And I press "Cancel"
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
# Radio - Checking "I set the field" and "the field matches value".
And I add a "Choice" to section "1" and I fill the form with:
| Choice name | Test choice name |
And the field "one" matches value "1"
And the field "two" matches value ""
# Check if field xpath set/match works.
- And I am on site homepage
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I navigate to "Edit settings" node in "Course administration"
And I set the field with xpath "//input[@id='id_idnumber']" to "Course id number"
And the field with xpath "//input[@name='idnumber']" matches value "Course id number"
@javascript
Scenario: with JS enabled all form fields getters and setters works as expected
- Then I follow "Course 1"
+ Then I am on "Course 1" course homepage
And I navigate to "Users > Groups" in current page administration
# Select (multi-select & AJAX) - Checking "I set the field" and "select box should contain".
And I set the field "groups" to "Group 2"
And the "members" select box should contain "Student 2"
And the "members" select box should not contain "Student 3"
# Checkbox (AJAX) - Checking "I set the field" and "I set the following fields to these values".
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I add a "Lesson" to section "1"
And I set the following fields to these values:
| Name | Test lesson |
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And I log in as "admin"
- And I am on site homepage
- And I follow "Course 1"
- And I turn editing mode on
+ And I am on "Course 1" course homepage with editing mode on
And I add a "Quiz" to section "1"
When I expand all fieldsets
Then I should see "Close the quiz"
| Custom description | Froggy file |
And I press "Save changes"
# Create a resource activity and add it to a course
- And I am on site homepage
- And I follow "Course 1"
- And I turn editing mode on
+ And I am on "Course 1" course homepage with editing mode on
When I add a "File" to section "1"
And I set the following fields to these values:
| Name | An example of customised file type |
$settings->frontpageloggedin = $CFG->frontpageloggedin;
$settings->maxcategorydepth = $CFG->maxcategorydepth;
$settings->frontpagecourselimit = $CFG->frontpagecourselimit;
- $settings->numsections = course_get_format($SITE)->get_course()->numsections;
+ $settings->numsections = course_get_format($SITE)->get_last_section_number();
$settings->newsitems = $SITE->newsitems;
$settings->commentsperpage = $CFG->commentsperpage;
array('name' => 'frontpageloggedin', 'value' => $CFG->frontpageloggedin),
array('name' => 'maxcategorydepth', 'value' => $CFG->maxcategorydepth),
array('name' => 'frontpagecourselimit', 'value' => $CFG->frontpagecourselimit),
- array('name' => 'numsections', 'value' => course_get_format($SITE)->get_course()->numsections),
+ array('name' => 'numsections', 'value' => course_get_format($SITE)->get_last_section_number()),
array('name' => 'newsitems', 'value' => $SITE->newsitems),
array('name' => 'commentsperpage', 'value' => $CFG->commentsperpage),
array('name' => 'disableuserimages', 'value' => $CFG->disableuserimages),
And I navigate to "Event monitoring rules" node in "Site administration > Reports"
And I click on "Enable" "link"
And I am on site homepage
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I navigate to "Event monitoring rules" node in "Course administration > Reports"
And I press "Add a new rule"
And I set the following fields to these values:
Scenario: Add a rule on course level
Given I log in as "teacher1"
- And I am on site homepage
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I navigate to "Event monitoring rules" node in "Course administration > Reports"
When I press "Add a new rule"
And I set the following fields to these values:
Scenario: Delete a rule on course level
Given I log in as "teacher1"
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I navigate to "Event monitoring rules" node in "Course administration > Reports"
When I click on "Delete rule" "link"
Then I should see "Are you sure you want to delete the rule \"New rule course level\"?"
Scenario: Edit a rule on course level
Given I log in as "teacher1"
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I navigate to "Event monitoring rules" node in "Course administration > Reports"
When I click on "Edit rule" "link"
And I set the following fields to these values:
Scenario: Duplicate a rule on course level
Given I log in as "teacher1"
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I navigate to "Event monitoring rules" node in "Course administration > Reports"
When I click on "Duplicate rule" "link" in the "New rule course level" "table_row"
Then I should see "Rule successfully duplicated"
Scenario: Duplicate a rule on site level
Given I log in as "teacher1"
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I navigate to "Event monitoring rules" node in "Course administration > Reports"
When I click on "Duplicate rule" "link" in the "New rule site level" "table_row"
Then I should see "Rule successfully duplicated"
And I log in as "admin"
And I navigate to "Event monitoring rules" node in "Site administration > Reports"
And I click on "Enable" "link"
- And I am on site homepage
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I navigate to "Event monitoring rules" node in "Course administration > Reports"
And I press "Add a new rule"
And I set the following fields to these values:
And I follow "Subscribe to rule \"New rule course level\""
And I should see "Subscription successfully created"
And "#toolmonitorsubs_r0" "css_element" should exist
- And I am on site homepage
- And I follow "Course 1"
+ And I am on "Course 1" course homepage
And I trigger cron
And I am on site homepage
When I click on ".popover-region-notifications" "css_element"
--- /dev/null
+<?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/>.
+
+/**
+ * This file contains the form add/update oauth2 endpoint.
+ *
+ * @package tool_oauth2
+ * @copyright 2017 Damyon Wiese
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace tool_oauth2\form;
+defined('MOODLE_INTERNAL') || die();
+
+use stdClass;
+use core\form\persistent;
+
+/**
+ * Issuer form.
+ *
+ * @package tool_oauth2
+ * @copyright 2017 Damyon Wiese
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class endpoint extends persistent {
+
+ /** @var string $persistentclass */
+ protected static $persistentclass = 'core\\oauth2\\endpoint';
+
+ /** @var array $fieldstoremove */
+ protected static $fieldstoremove = array('submitbutton', 'action');
+
+ /**
+ * Define the form - called by parent constructor
+ */
+ public function definition() {
+ global $PAGE;
+
+ $mform = $this->_form;
+ $endpoint = $this->get_persistent();
+
+ // Name.
+ $mform->addElement('text', 'name', get_string('endpointname', 'tool_oauth2'));
+ $mform->addRule('name', null, 'required', null, 'client');
+ $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
+ $mform->addHelpButton('name', 'endpointname', 'tool_oauth2');
+
+ // Url.
+ $mform->addElement('text', 'url', get_string('endpointurl', 'tool_oauth2'));
+ $mform->addRule('url', null, 'required', null, 'client');
+ $mform->addRule('url', get_string('maximumchars', '', 1024), 'maxlength', 1024, 'client');
+ $mform->addHelpButton('url', 'endpointurl', 'tool_oauth2');
+
+ $mform->addElement('hidden', 'action', 'edit');
+ $mform->setType('action', PARAM_ALPHA);
+
+ $mform->addElement('hidden', 'issuerid', $endpoint->get('issuerid'));
+ $mform->setType('issuerid', PARAM_INT);
+ $mform->setConstant('issuerid', $this->_customdata['issuerid']);
+
+ $mform->addElement('hidden', 'id', $endpoint->get('id'));
+ $mform->setType('id', PARAM_INT);
+
+ $this->add_action_buttons(true, get_string('savechanges', 'tool_oauth2'));
+ }
+
+}
+
--- /dev/null
+<?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/>.
+
+/**
+ * This file contains the form add/update oauth2 issuer.
+ *
+ * @package tool_oauth2
+ * @copyright 2017 Damyon Wiese
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace tool_oauth2\form;
+defined('MOODLE_INTERNAL') || die();
+
+use stdClass;
+use core\form\persistent;
+
+/**
+ * Issuer form.
+ *
+ * @package tool_oauth2
+ * @copyright 2017 Damyon Wiese
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class issuer extends persistent {
+
+ /** @var string $persistentclass */
+ protected static $persistentclass = 'core\\oauth2\\issuer';
+
+ /** @var array $fieldstoremove */
+ protected static $fieldstoremove = array('submitbutton', 'action');
+
+ /**
+ * Define the form - called by parent constructor
+ */
+ public function definition() {
+ global $PAGE, $OUTPUT;
+
+ $mform = $this->_form;
+ $issuer = $this->get_persistent();
+
+ $docslink = optional_param('docslink', '', PARAM_ALPHAEXT);
+ if ($docslink) {
+ $name = s($issuer->get('name'));
+ $mform->addElement('html', $OUTPUT->doc_link($docslink, get_string('issuersetuptype', 'tool_oauth2', $name)));
+ } else {
+ $mform->addElement('html', $OUTPUT->page_doc_link(get_string('issuersetup', 'tool_oauth2')));
+ }
+
+ // Name.
+ $mform->addElement('text', 'name', get_string('issuername', 'tool_oauth2'));
+ $mform->addRule('name', null, 'required', null, 'client');
+ $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
+ $mform->addHelpButton('name', 'issuername', 'tool_oauth2');
+
+ // Client ID.
+ $mform->addElement('text', 'clientid', get_string('issuerclientid', 'tool_oauth2'));
+ $mform->addRule('clientid', null, 'required', null, 'client');
+ $mform->addRule('clientid', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
+ $mform->addHelpButton('clientid', 'issuerclientid', 'tool_oauth2');
+
+ // Client Secret.
+ $mform->addElement('text', 'clientsecret', get_string('issuerclientsecret', 'tool_oauth2'));
+ $mform->addRule('clientsecret', null, 'required', null, 'client');
+ $mform->addRule('clientsecret', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
+ $mform->addHelpButton('clientsecret', 'issuerclientsecret', 'tool_oauth2');
+
+ // Login scopes.
+ $mform->addElement('text', 'loginscopes', get_string('issuerloginscopes', 'tool_oauth2'));
+ $mform->addRule('loginscopes', null, 'required', null, 'client');
+ $mform->addRule('loginscopes', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
+ $mform->addHelpButton('loginscopes', 'issuerloginscopes', 'tool_oauth2');
+
+ // Login scopes offline.
+ $mform->addElement('text', 'loginscopesoffline', get_string('issuerloginscopesoffline', 'tool_oauth2'));
+ $mform->addRule('loginscopesoffline', null, 'required', null, 'client');
+ $mform->addRule('loginscopesoffline', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
+ $mform->addHelpButton('loginscopesoffline', 'issuerloginscopesoffline', 'tool_oauth2');
+
+ // Login params.
+ $mform->addElement('text', 'loginparams', get_string('issuerloginparams', 'tool_oauth2'));
+ $mform->addRule('loginparams', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
+ $mform->addHelpButton('loginparams', 'issuerloginparams', 'tool_oauth2');
+
+ // Login params offline.
+ $mform->addElement('text', 'loginparamsoffline', get_string('issuerloginparamsoffline', 'tool_oauth2'));
+ $mform->addRule('loginparamsoffline', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
+ $mform->addHelpButton('loginparamsoffline', 'issuerloginparamsoffline', 'tool_oauth2');
+
+ // Base Url.
+ $mform->addElement('text', 'baseurl', get_string('issuerbaseurl', 'tool_oauth2'));
+ $mform->addRule('baseurl', get_string('maximumchars', '', 1024), 'maxlength', 1024, 'client');
+ $mform->addHelpButton('baseurl', 'issuerbaseurl', 'tool_oauth2');
+
+ // Allowed Domains.
+ $mform->addElement('text', 'alloweddomains', get_string('issueralloweddomains', 'tool_oauth2'));
+ $mform->addRule('alloweddomains', get_string('maximumchars', '', 1024), 'maxlength', 1024, 'client');
+ $mform->addHelpButton('alloweddomains', 'issueralloweddomains', 'tool_oauth2');
+
+ // Image.
+ $mform->addElement('text', 'image', get_string('issuerimage', 'tool_oauth2'), 'maxlength="1024"');
+ $mform->addRule('image', get_string('maximumchars', '', 1024), 'maxlength', 1024, 'client');
+ $mform->addHelpButton('image', 'issuername', 'tool_oauth2');
+
+ // Show on login page.
+ $mform->addElement('checkbox', 'showonloginpage', get_string('issuershowonloginpage', 'tool_oauth2'));
+ $mform->addHelpButton('showonloginpage', 'issuershowonloginpage', 'tool_oauth2');
+
+ $mform->addElement('hidden', 'sortorder');
+ $mform->setType('sortorder', PARAM_INT);
+
+ $mform->addElement('hidden', 'action', 'edit');
+ $mform->setType('action', PARAM_ALPHA);
+
+ $mform->addElement('hidden', 'enabled', $issuer->get('enabled'));
+ $mform->setType('enabled', PARAM_BOOL);
+
+ $mform->addElement('hidden', 'id', $issuer->get('id'));
+ $mform->setType('id', PARAM_INT);
+
+ $this->add_action_buttons(true, get_string('savechanges', 'tool_oauth2'));
+ }
+
+}
+
--- /dev/null
+<?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/>.
+
+/**
+ * This file contains the form add/update oauth2 user_field_mapping.
+ *
+ * @package tool_oauth2
+ * @copyright 2017 Damyon Wiese
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+namespace tool_oauth2\form;
+defined('MOODLE_INTERNAL') || die();
+
+use stdClass;
+use core\form\persistent;
+
+/**
+ * Issuer form.
+ *
+ * @package tool_oauth2
+ * @copyright 2017 Damyon Wiese
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class user_field_mapping extends persistent {
+
+ /** @var string $persistentclass */
+ protected static $persistentclass = 'core\\oauth2\\user_field_mapping';
+
+ /** @var array $fieldstoremove */
+ protected static $fieldstoremove = array('submitbutton', 'action');
+
+ /**
+ * Define the form - called by parent constructor
+ */
+ public function definition() {
+ global $PAGE;
+
+ $mform = $this->_form;
+ $userfieldmapping = $this->get_persistent();
+
+ // External.
+ $mform->addElement('text', 'externalfield', get_string('userfieldexternalfield', 'tool_oauth2'));
+ $mform->addRule('externalfield', null, 'required', null, 'client');
+ $mform->addRule('externalfield', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
+ $mform->addHelpButton('externalfield', 'userfieldexternalfield', 'tool_oauth2');
+
+ // Internal.
+ $choices = $userfieldmapping->get_internalfield_list();
+ $mform->addElement('select', 'internalfield', get_string('userfieldinternalfield', 'tool_oauth2'), $choices);
+ $mform->addHelpButton('internalfield', 'userfieldinternalfield', 'tool_oauth2');
+
+ $mform->addElement('hidden', 'action', 'edit');
+ $mform->setType('action', PARAM_ALPHA);
+
+ $mform->addElement('hidden', 'issuerid', $userfieldmapping->get('issuerid'));
+ $mform->setConstant('issuerid', $this->_customdata['issuerid']);
+ $mform->setType('issuerid', PARA