Update Copywrite year to be 2019
[civicrm-core.git] / CRM / Admin / Form / SettingTrait.php
index fafae4f4d67403350dd46b848eb7614578c42ad8..bbc755092621ec79714e44f1b2f8f4bd1ce817e9 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018                                |
+ | Copyright CiviCRM LLC (c) 2004-2019                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2018
+ * @copyright CiviCRM LLC (c) 2004-2019
  */
 
 /**
@@ -127,7 +127,7 @@ trait CRM_Admin_Form_SettingTrait {
     foreach ($settingMetaData as $setting => $props) {
       $quickFormType = $this->getQuickFormType($props);
       if (isset($quickFormType)) {
-        $options = NULL;
+        $options = CRM_Utils_Array::value('options', $props);
         if (isset($props['pseudoconstant'])) {
           $options = civicrm_api3('Setting', 'getoptions', [
             'field' => $setting,
@@ -143,11 +143,6 @@ trait CRM_Admin_Form_SettingTrait {
           $this->includesReadOnlyFields = TRUE;
         }
 
-        if (isset($props['help_link'])) {
-          // Set both the value in this loop & the outer value as we assign both to the template while we deprecate the $descriptions assignment.
-          $settingMetaData[$setting]['description'] = $props['description'] .= ' ' . CRM_Utils_System::docURL2($props['help_link']['page'], NULL, NULL, NULL, NULL, $props['help_link']['resource']);
-
-        }
         $add = 'add' . $quickFormType;
         if ($add == 'addElement') {
           $this->$add(
@@ -162,7 +157,7 @@ trait CRM_Admin_Form_SettingTrait {
           $this->addElement('select', $setting, ts($props['title']), $options, CRM_Utils_Array::value('html_attributes', $props));
         }
         elseif ($add == 'addCheckBox') {
-          $this->addCheckBox($setting, ts($props['title']), $options, NULL, CRM_Utils_Array::value('html_attributes', $props), NULL, NULL, ['  ']);
+          $this->addCheckBox($setting, '', $options, NULL, CRM_Utils_Array::value('html_attributes', $props), NULL, NULL, ['  ']);
         }
         elseif ($add == 'addCheckBoxes') {
           $options = array_flip($options);
@@ -188,12 +183,16 @@ trait CRM_Admin_Form_SettingTrait {
         elseif ($add === 'addEntityRef') {
           $this->$add($setting, ts($props['title']), $props['entity_reference_options']);
         }
+        elseif ($add === 'addYesNo' && ($props['type'] === 'Boolean')) {
+          $this->addRadio($setting, ts($props['title']), array(1 => 'Yes', 0 => 'No'), NULL, '  ');
+        }
         else {
           $this->$add($setting, ts($props['title']), $options);
         }
         // Migrate to using an array as easier in smart...
-        $descriptions[$setting] = ts($props['description']);
-        $this->assign("{$setting}_description", ts($props['description']));
+        $description = CRM_Utils_Array::value('description', $props);
+        $descriptions[$setting] = $description;
+        $this->assign("{$setting}_description", $description);
         if ($setting == 'max_attachments') {
           //temp hack @todo fix to get from metadata
           $this->addRule('max_attachments', ts('Value should be a positive number'), 'positiveInteger');
@@ -221,8 +220,17 @@ trait CRM_Admin_Form_SettingTrait {
   protected function getQuickFormType($spec) {
     if (isset($spec['quick_form_type']) &&
     !($spec['quick_form_type'] === 'Element' && !empty($spec['html_type']))) {
+      // This is kinda transitional
       return $spec['quick_form_type'];
     }
+
+    // The spec for settings has been updated for consistency - we provide deprecation notices for sites that have
+    // not made this change.
+    $htmlType = $spec['html_type'];
+    if ($htmlType !== strtolower($htmlType)) {
+      CRM_Core_Error::deprecatedFunctionWarning(ts('Settings fields html_type should be lower case - see https://docs.civicrm.org/dev/en/latest/framework/setting/ - this needs to be fixed for ' . $spec['name']));
+      $htmlType = strtolower($spec['html_type']);
+    }
     $mapping = [
       'checkboxes' => 'CheckBoxes',
       'checkbox' => 'CheckBox',
@@ -231,8 +239,9 @@ trait CRM_Admin_Form_SettingTrait {
       'textarea' => 'Element',
       'text' => 'Element',
       'entity_reference' => 'EntityRef',
+      'advmultiselect' => 'Element',
     ];
-    return $mapping[$spec['html_type']];
+    return $mapping[$htmlType];
   }
   /**
    * Get the defaults for all fields defined in the metadata.