CRM-13992 coding neccessary property values / configurable options required for tab...
[civicrm-core.git] / CRM / Custom / Form / Field.php
index b573587d9fccfdacf48309540f44c99fe7825f6e..05988af601eb41e799896a01d00cc00bc75c6c2d 100644 (file)
@@ -190,7 +190,7 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
         $defaults['default_value'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Country', $countryId);
       }
 
-      if ($defaults['data_type'] == 'ContactReference' && CRM_Utils_Array::value('filter', $defaults)) {
+      if ($defaults['data_type'] == 'ContactReference' && !empty($defaults['filter'])) {
         $contactRefFilter = 'Advance';
         if (strpos($defaults['filter'], 'action=lookup') !== FALSE &&
           strpos($defaults['filter'], 'group=') !== FALSE
@@ -215,7 +215,7 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
         $defaults['filter_selected'] = $contactRefFilter;
       }
 
-      if (CRM_Utils_Array::value('data_type', $defaults)) {
+      if (!empty($defaults['data_type'])) {
         $defaultDataType = array_search($defaults['data_type'],
           self::$_dataTypeKeys
         );
@@ -254,13 +254,17 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
       $defaults['is_view'] = 0;
     }
 
-    if (CRM_Utils_Array::value('html_type', $defaults)) {
+    if (!empty($defaults['html_type'])) {
       $dontShowLink = substr($defaults['html_type'], -14) == 'State/Province' || substr($defaults['html_type'], -7) == 'Country' ? 1 : 0;
     }
 
     if (isset($dontShowLink)) {
       $this->assign('dontShowLink', $dontShowLink);
     }
+    if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_multiple', 'id')) {
+      $defaults['in_selector'] = 1;
+    }
+
     return $defaults;
   }
 
@@ -304,6 +308,11 @@ class CRM_Custom_Form_Field extends CRM_Core_Form {
       '   '
     );
     $sel->setOptions(array($dt, $it));
+
+    if (CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_gid, 'is_multiple')) {
+      $this->add('checkbox', 'in_selector', ts('Display in Table?'));
+    }
+
     if ($this->_action == CRM_Core_Action::UPDATE) {
       $this->freeze('data_type');
     }
@@ -660,9 +669,7 @@ SELECT count(*)
           break;
 
         case 'ContactReference':
-          if ($fields['filter_selected'] == 'Advance' &&
-            CRM_Utils_Array::value('filter', $fields)
-          ) {
+          if ($fields['filter_selected'] == 'Advance' && !empty($fields['filter'])) {
             if (strpos($fields['filter'], 'entity=') !== FALSE) {
               $errors['filter'] = ts("Please do not include entity parameter (entity is always 'contact')");
             }
@@ -876,9 +883,7 @@ AND    option_group_id = %2";
     }
 
     // we can not set require and view at the same time.
-    if (CRM_Utils_Array::value('is_required', $fields) &&
-      CRM_Utils_Array::value('is_view', $fields)
-    ) {
+    if (!empty($fields['is_required']) && !empty($fields['is_view'])) {
       $errors['is_view'] = ts('Can not set this field Required and View Only at the same time.');
     }
 
@@ -910,7 +915,7 @@ AND    option_group_id = %2";
     //fix for 'is_search_range' field.
     if (in_array($dataTypeKey, array(
       1, 2, 3, 5))) {
-      if (!CRM_Utils_Array::value('is_searchable', $params)) {
+      if (empty($params['is_searchable'])) {
         $params['is_search_range'] = 0;
       }
     }
@@ -919,11 +924,11 @@ AND    option_group_id = %2";
     }
 
     $filter = 'null';
-    if ($dataTypeKey == 11 && CRM_Utils_Array::value('filter_selected', $params)) {
+    if ($dataTypeKey == 11 && !empty($params['filter_selected'])) {
       if ($params['filter_selected'] == 'Advance' && trim(CRM_Utils_Array::value('filter', $params))) {
         $filter = trim($params['filter']);
       }
-      elseif ($params['filter_selected'] == 'Group' && CRM_Utils_Array::value('group_id', $params)) {
+      elseif ($params['filter_selected'] == 'Group' && !empty($params['group_id'])) {
 
         $filter = 'action=lookup&group=' . implode(',', $params['group_id']);
       }