Merge pull request #10496 from jitendrapurohit/CRM-20719
[civicrm-core.git] / CRM / Admin / Form / Setting.php
index c378b53d80618adfe48902a888389a92e0aa7bc3..f7ed1b624651a5f2baa5b4c7d5fc03bc975da219 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2017                                |
+ | Copyright CiviCRM LLC (c) 2004-2018                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2017
+ * @copyright CiviCRM LLC (c) 2004-2018
  */
 
 /**
@@ -98,27 +98,18 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
     foreach ($settingMetaData as $setting => $props) {
       if (isset($props['quick_form_type'])) {
         if (isset($props['pseudoconstant'])) {
-          if (array_key_exists('optionGroupName', $props['pseudoconstant'])) {
-            $optionValues = civicrm_api3('OptionValue', 'get', array(
-              'return' => array("label", "value"),
-              'option_group_id' => $setting,
-            ));
-            if ($optionValues['count'] > 0) {
-              foreach ($optionValues['values'] as $key => $values) {
-                $vals[$values['value']] = $values['label'];
-              }
-              $options['values'] = $vals;
-            }
-          }
-          else {
-            $options = civicrm_api3('Setting', 'getoptions', array(
-              'field' => $setting,
-            ));
-          }
+          $options = civicrm_api3('Setting', 'getoptions', array(
+            'field' => $setting,
+          ));
         }
         else {
           $options = NULL;
         }
+        //Load input as readonly whose values are overridden in civicrm.settings.php.
+        if (Civi::settings()->getMandatory($setting)) {
+          $props['html_attributes']['readonly'] = TRUE;
+          $setStatus = TRUE;
+        }
 
         $add = 'add' . $props['quick_form_type'];
         if ($add == 'addElement') {
@@ -131,11 +122,7 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
           );
         }
         elseif ($add == 'addSelect') {
-          $element = $this->addElement('select', $setting, ts($props['title']), $options['values'], CRM_Utils_Array::value('html_attributes', $props));
-          if (defined('CIVICRM_ENVIRONMENT')) {
-            $element->freeze();
-            CRM_Core_Session::setStatus(ts('The environment settings have been disabled because it has been overridden in the settings file.'), ts('Environment settings'), 'info');
-          }
+          $this->addElement('select', $setting, ts($props['title']), $options['values'], CRM_Utils_Array::value('html_attributes', $props));
         }
         elseif ($add == 'addCheckBox') {
           $this->addCheckBox($setting, ts($props['title']), $options['values'], NULL, CRM_Utils_Array::value('html_attributes', $props), NULL, NULL, array('  '));
@@ -165,6 +152,9 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
 
       }
     }
+    if (!empty($setStatus)) {
+      CRM_Core_Session::setStatus(ts("Some fields are loaded as 'readonly' as they have been set (overridden) in civicrm.settings.php."), '', 'info', array('expires' => 0));
+    }
     // setting_description should be deprecated - see Mail.tpl for metadata based tpl.
     $this->assign('setting_descriptions', $descriptions);
     $this->assign('settings_fields', $settingMetaData);