mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-29807 Control to avoid duplicate shortnames
This commit is contained in:
parent
b129859207
commit
0a8ab74728
2 changed files with 15 additions and 0 deletions
|
@ -69,6 +69,10 @@ class external_service_form extends moodleform {
|
||||||
|
|
||||||
$mform->addElement('text', 'shortname', get_string('shortname'), 'maxlength="255" size="20"');
|
$mform->addElement('text', 'shortname', get_string('shortname'), 'maxlength="255" size="20"');
|
||||||
$mform->setType('shortname', PARAM_TEXT);
|
$mform->setType('shortname', PARAM_TEXT);
|
||||||
|
if (!empty($service->id)) {
|
||||||
|
$mform->hardFreeze('shortname');
|
||||||
|
$mform->setConstants('shortname', $service->shortname);
|
||||||
|
}
|
||||||
|
|
||||||
$mform->addElement('advcheckbox', 'enabled', get_string('enabled', 'webservice'));
|
$mform->addElement('advcheckbox', 'enabled', get_string('enabled', 'webservice'));
|
||||||
$mform->setType('enabled', PARAM_BOOL);
|
$mform->setType('enabled', PARAM_BOOL);
|
||||||
|
@ -149,7 +153,17 @@ class external_service_form extends moodleform {
|
||||||
}
|
}
|
||||||
|
|
||||||
function validation($data, $files) {
|
function validation($data, $files) {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
$errors = parent::validation($data, $files);
|
$errors = parent::validation($data, $files);
|
||||||
|
|
||||||
|
// Add field validation check for duplicate shortname.
|
||||||
|
if ($service = $DB->get_record('external_services', array('shortname' => $data['shortname']), '*', IGNORE_MULTIPLE)) {
|
||||||
|
if (empty($data['id']) || $service->id != $data['id']) {
|
||||||
|
$errors['shortname'] = get_string('shortnametaken', 'webservice', $service->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $errors;
|
return $errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -176,6 +176,7 @@ $string['serviceusers'] = 'Authorised users';
|
||||||
$string['serviceusersettings'] = 'User settings';
|
$string['serviceusersettings'] = 'User settings';
|
||||||
$string['serviceusersmatching'] = 'Authorised users matching';
|
$string['serviceusersmatching'] = 'Authorised users matching';
|
||||||
$string['serviceuserssettings'] = 'Change settings for the authorised users';
|
$string['serviceuserssettings'] = 'Change settings for the authorised users';
|
||||||
|
$string['shortnametaken'] = 'Short name is already used for another service ({$a})';
|
||||||
$string['simpleauthlog'] = 'Simple authentication login';
|
$string['simpleauthlog'] = 'Simple authentication login';
|
||||||
$string['step'] = 'Step';
|
$string['step'] = 'Step';
|
||||||
$string['supplyinfo'] = 'More details';
|
$string['supplyinfo'] = 'More details';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue