Skip to content

Commit

Permalink
MDL-17074 - backport ability of admin settings to use the config_plug…
Browse files Browse the repository at this point in the history
…ins table
  • Loading branch information
stronk7 committed Feb 11, 2009
1 parent 50537ba commit d2aa927
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions lang/en_utf8/error.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
$string['guestnoeditprofile'] = 'The guest user cannot edit their profile';
$string['guestnoeditprofileother'] = 'The guest user profile cannot be edited';
$string['guestsarenotallowed'] = 'The guest user is not allowed to do this';
$string['invalidadminsettingname'] = 'Invalid admin setting ($a)';
$string['invalidcontext'] = 'Invalid context';
$string['invalidcourse'] = 'Invalid course';
$string['invalidcourseid'] = 'You are trying to use an invalid course ID ($a)';
Expand Down
29 changes: 28 additions & 1 deletion lib/adminlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1616,12 +1616,39 @@ class admin_setting {
* @param mixed $defaultsetting string or array depending on implementation
*/
function admin_setting($name, $visiblename, $description, $defaultsetting) {
$this->name = $name;
$this->parse_setting_name($name);
$this->visiblename = $visiblename;
$this->description = $description;
$this->defaultsetting = $defaultsetting;
}

/**
* Set up $this->name and possibly $this->plugin based on whether $name looks
* like 'settingname' or 'plugin/settingname'. Also, do some sanity checking
* on the names, that is, output a developer debug warning if the name
* contains anything other than [a-zA-Z0-9_]+.
*
* @param string $name the setting name passed in to the constructor.
*/
function parse_setting_name($name) {
$bits = explode('/', $name);
if (count($bits) > 2) {
print_error('invalidadminsettingname', '', '', $name);
}
$this->name = array_pop($bits);
if (!preg_match('/^[a-zA-Z0-9_]+$/', $this->name)) {
print_error('invalidadminsettingname', '', '', $name);
}
if (!empty($bits)) {
$this->plugin = array_pop($bits);
if ($this->plugin === 'moodle') {
$this->plugin = null;
} else if (!preg_match('/^[a-zA-Z0-9_]+$/', $this->plugin)) {
print_error('invalidadminsettingname', '', '', $name);
}
}
}

function get_full_name() {
return 's_'.$this->plugin.'_'.$this->name;
}
Expand Down

0 comments on commit d2aa927

Please sign in to comment.