Merge branch 'MDL-50406_master' of git://github.com/nadavkav/moodle
authorDan Poltawski <dan@moodle.com>
Mon, 1 Jun 2015 10:42:22 +0000 (11:42 +0100)
committerDan Poltawski <dan@moodle.com>
Mon, 1 Jun 2015 10:42:22 +0000 (11:42 +0100)
admin/tool/messageinbound/settings.php
lib/adminlib.php
lib/db/upgrade.php

index 72d23ab..bb562e0 100644 (file)
@@ -41,9 +41,9 @@ if ($hassiteconfig) {
     $settings->add(new admin_setting_heading('messageinbound_mailboxconfiguration',
             new lang_string('mailboxconfiguration', 'tool_messageinbound'),
             new lang_string('messageinboundmailboxconfiguration_desc', 'tool_messageinbound'), ''));
-    $settings->add(new admin_setting_configtext('messageinbound_mailbox',
+    $settings->add(new admin_setting_configtext_with_maxlength('messageinbound_mailbox',
             new lang_string('mailbox', 'tool_messageinbound'),
-            null, '', PARAM_RAW));
+            null, '', PARAM_RAW, null, 15));
     $settings->add(new admin_setting_configtext('messageinbound_domain',
             new lang_string('domain', 'tool_messageinbound'),
             null, '', PARAM_RAW));
index 485a710..380d1d5 100644 (file)
@@ -2182,6 +2182,59 @@ class admin_setting_configtext extends admin_setting {
     }
 }
 
+/**
+ * Text input with a maximum length constraint.
+ *
+ * @copyright 2015 onwards Ankit Agarwal
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class admin_setting_configtext_with_maxlength extends admin_setting_configtext {
+
+    /** @var int maximum number of chars allowed. */
+    protected $maxlength;
+
+    /**
+     * Config text constructor
+     *
+     * @param string $name unique ascii name, either 'mysetting' for settings that in config,
+     *                     or 'myplugin/mysetting' for ones in config_plugins.
+     * @param string $visiblename localised
+     * @param string $description long localised info
+     * @param string $defaultsetting
+     * @param mixed $paramtype int means PARAM_XXX type, string is a allowed format in regex
+     * @param int $size default field size
+     * @param mixed $maxlength int maxlength allowed, 0 for infinite.
+     */
+    public function __construct($name, $visiblename, $description, $defaultsetting, $paramtype=PARAM_RAW,
+                                $size=null, $maxlength = 0) {
+        $this->maxlength = $maxlength;
+        parent::__construct($name, $visiblename, $description, $defaultsetting, $paramtype, $size);
+    }
+
+    /**
+     * Validate data before storage
+     *
+     * @param string $data data
+     * @return mixed true if ok string if error found
+     */
+    public function validate($data) {
+        $parentvalidation = parent::validate($data);
+        if ($parentvalidation === true) {
+            if ($this->maxlength > 0) {
+                // Max length check.
+                $length = core_text::strlen($data);
+                if ($length > $this->maxlength) {
+                    return get_string('maximumchars', 'moodle',  $this->maxlength);
+                }
+                return true;
+            } else {
+                return true; // No max length check needed.
+            }
+        } else {
+            return $parentvalidation;
+        }
+    }
+}
 
 /**
  * General text area without html editor.
index 4da08aa..3bfd0ba 100644 (file)
@@ -4308,7 +4308,7 @@ function xmldb_main_upgrade($oldversion) {
         // Add "My grades" to the user menu.
         $oldconfig = get_config('core', 'customusermenuitems');
         if (strpos("mygrades,grades|/grade/report/mygrades.php|grades", $oldconfig) === false) {
-            $newconfig = "mygrades,grades|/grade/report/mygrades.php|grades\n" . $CFG->customusermenuitems;
+            $newconfig = "mygrades,grades|/grade/report/mygrades.php|grades\n" . $oldconfig;
             set_config('customusermenuitems', $newconfig);
         }