From f0211bbfb1d63b8e55a26ec0fea0033e7cbc33da Mon Sep 17 00:00:00 2001 From: Stevani Andolo Date: Fri, 26 May 2023 11:09:14 +0800 Subject: [PATCH] MDL-75937 admin: Fixed config data display inconsistency --- lib/adminlib.php | 52 ++++++++++++++++++++++++++++++++++++++++++++++-- lib/upgrade.txt | 5 +++++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/lib/adminlib.php b/lib/adminlib.php index 6d04ea2a076..840d606742e 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -1816,7 +1816,7 @@ abstract class admin_setting { global $CFG; if (empty($this->plugin)) { - if (array_key_exists($this->name, $CFG->config_php_settings)) { + if ($this->is_forceable() && array_key_exists($this->name, $CFG->config_php_settings)) { return true; } } else { @@ -2160,6 +2160,18 @@ abstract class admin_setting { public function has_custom_form_control(): bool { return $this->customcontrol; } + + /** + * Whether the setting can be overridden in config.php. + * + * Returning true will allow the setting to be defined and overridden in config.php. + * Returning false will prevent the config setting from being overridden even when it gets defined in config.php. + * + * @return bool + */ + public function is_forceable(): bool { + return true; + } } /** @@ -4545,6 +4557,15 @@ class admin_setting_sitesetselect extends admin_setting_configselect { return ''; } + + /** + * admin_setting_sitesetselect is not meant to be overridden in config.php. + * + * @return bool + */ + public function is_forceable(): bool { + return false; + } } @@ -4755,6 +4776,15 @@ class admin_setting_sitesetcheckbox extends admin_setting_configcheckbox { return ''; } + + /** + * admin_setting_sitesetcheckbox is not meant to be overridden in config.php. + * + * @return bool + */ + public function is_forceable(): bool { + return false; + } } /** @@ -4837,6 +4867,15 @@ class admin_setting_sitesettext extends admin_setting_configtext { return ''; } + + /** + * admin_setting_sitesettext is not meant to be overridden in config.php. + * + * @return bool + */ + public function is_forceable(): bool { + return false; + } } @@ -4912,6 +4951,15 @@ class admin_setting_special_frontpagedesc extends admin_setting_confightmleditor return ''; } + + /** + * admin_setting_special_frontpagedesc is not meant to be overridden in config.php. + * + * @return bool + */ + public function is_forceable(): bool { + return false; + } } @@ -9162,7 +9210,7 @@ function format_admin_setting($setting, $title='', $form='', $description='', $l $context->warning = $warning; $context->override = ''; if (empty($setting->plugin)) { - if (array_key_exists($setting->name, $CFG->config_php_settings)) { + if ($setting->is_forceable() && array_key_exists($setting->name, $CFG->config_php_settings)) { $context->override = get_string('configoverride', 'admin'); } } else { diff --git a/lib/upgrade.txt b/lib/upgrade.txt index 3cf9fb3b5bd..3bdc64d97bb 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -1,6 +1,11 @@ This files describes API changes in core libraries and APIs, information provided here is intended especially for developers. +=== 4.1.5 === +* Added new \admin_setting::is_forceable() method to determine whether the setting can be overridden or not. Therefore, + whether the settings can be overriden or not will depend on the value of implemented \admin_setting::is_forceable() method, + even if we define the settings in config.php. + === 4.1.4 === * Added a new parameter in address_in_subnet to give us the ability to check for 0.0.0.0 or not.