From 627bfa5d1ad65a60bdb6b0bfcd0f434582f68945 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Thu, 6 Mar 2025 15:25:55 +0000 Subject: [PATCH] MDL-84763 customfield: increase size of category/field name fields. Allows for more flexibility for multi-lingual sites using filtered text. --- .../customfield/classes/field_config_form.php | 12 ++++++++++-- public/customfield/lib.php | 1 + public/lib/db/install.xml | 6 +++--- public/lib/db/upgrade.php | 19 +++++++++++++++++++ public/version.php | 2 +- 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/public/customfield/classes/field_config_form.php b/public/customfield/classes/field_config_form.php index 53d1b5f54a1..7528205d53e 100644 --- a/public/customfield/classes/field_config_form.php +++ b/public/customfield/classes/field_config_form.php @@ -51,16 +51,24 @@ class field_config_form extends \core_form\dynamic_form { $mform->addElement('header', '_commonsettings', get_string('commonsettings', 'core_customfield')); - $mform->addElement('text', 'name', get_string('fieldname', 'core_customfield'), 'size="50"'); + $mform->addElement('text', 'name', get_string('fieldname', 'core_customfield'), [ + 'size' => 50, + 'maxlength' => 1333, + ]); $mform->addRule('name', null, 'required', null, 'client'); + $mform->addRule('name', get_string('maximumchars', '', 1333), 'maxlength', 1333, 'client'); $mform->setType('name', PARAM_TEXT); // Accepted values for 'shortname' would follow [a-z0-9_] pattern, // but we are accepting any PARAM_TEXT value here, // and checking [a-zA-Z0-9_] pattern in validation() function to throw an error when needed. - $mform->addElement('text', 'shortname', get_string('fieldshortname', 'core_customfield'), 'size=20'); + $mform->addElement('text', 'shortname', get_string('fieldshortname', 'core_customfield'), [ + 'size' => 20, + 'maxlength' => 100, + ]); $mform->addHelpButton('shortname', 'shortname', 'core_customfield'); $mform->addRule('shortname', null, 'required', null, 'client'); + $mform->addRule('shortname', get_string('maximumchars', '', 100), 'maxlength', 100, 'client'); $mform->setType('shortname', PARAM_TEXT); $desceditoroptions = $handler->get_description_text_options(); diff --git a/public/customfield/lib.php b/public/customfield/lib.php index 2bb99f4807d..8b534d61eb8 100644 --- a/public/customfield/lib.php +++ b/public/customfield/lib.php @@ -43,6 +43,7 @@ function core_customfield_inplace_editable($itemtype, $itemid, $newvalue) { throw new moodle_exception('nopermissionconfigure', 'core_customfield'); } $newvalue = clean_param($newvalue, PARAM_TEXT); + $newvalue = core_text::substr($newvalue, 0, 1333); $handler->rename_category($category, $newvalue); return \core_customfield\api::get_category_inplace_editable($category, true); } diff --git a/public/lib/db/install.xml b/public/lib/db/install.xml index 95eed21f29a..d36e0286c54 100644 --- a/public/lib/db/install.xml +++ b/public/lib/db/install.xml @@ -1,5 +1,5 @@ - @@ -4282,7 +4282,7 @@ - + @@ -4306,7 +4306,7 @@ - + diff --git a/public/lib/db/upgrade.php b/public/lib/db/upgrade.php index f4425cfc7f8..dae3fca1b36 100644 --- a/public/lib/db/upgrade.php +++ b/public/lib/db/upgrade.php @@ -2295,5 +2295,24 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2025091600.01); } + if ($oldversion < 2025092200.00) { + // Changing precision of field name on table customfield_category to (1333). + $table = new xmldb_table('customfield_category'); + $field = new xmldb_field('name', XMLDB_TYPE_CHAR, '1333', null, XMLDB_NOTNULL, null, null, 'id'); + + // Launch change of precision for field name. + $dbman->change_field_precision($table, $field); + + // Changing precision of field name on table customfield_field to (1333). + $table = new xmldb_table('customfield_field'); + $field = new xmldb_field('name', XMLDB_TYPE_CHAR, '1333', null, XMLDB_NOTNULL, null, null, 'shortname'); + + // Launch change of precision for field name. + $dbman->change_field_precision($table, $field); + + // Main savepoint reached. + upgrade_main_savepoint(true, 2025092200.00); + } + return true; } diff --git a/public/version.php b/public/version.php index 25ceb3e88fe..cf4d6006cb7 100644 --- a/public/version.php +++ b/public/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2025091900.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2025092200.00; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '5.1dev+ (Build: 20250919)'; // Human-friendly version name