CRM-19769 - Add select2 widget to display tags in color
[civicrm-core.git] / CRM / Case / Form / Case.php
index 059fe437c781c1b2c7a524b6aa746f1b189f4257..f236b23dab0df199dbafb1fe69dda338812ccbb6 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015                                |
+ | Copyright CiviCRM LLC (c) 2004-2016                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2015
+ * @copyright CiviCRM LLC (c) 2004-2016
  */
 
 /**
@@ -111,17 +111,14 @@ class CRM_Case_Form_Case extends CRM_Core_Form {
 
     if (!$this->_caseId) {
       $caseAttributes = array(
-        'case_type' => CRM_Case_PseudoConstant::caseType(),
-        'case_status' => CRM_Case_PseudoConstant::caseStatus(),
-        'encounter_medium' => CRM_Case_PseudoConstant::encounterMedium(),
+        'case_type_id' => ts('Case Type'),
+        'status_id' => ts('Case Status'),
+        'medium_id' => ts('Activity Medium'),
       );
 
-      foreach ($caseAttributes as $key => $values) {
-        if (empty($values)) {
-          CRM_Core_Error::fatal(ts('You do not have any active %1',
-            array(1 => str_replace('_', ' ', $key))
-          ));
-          break;
+      foreach ($caseAttributes as $key => $label) {
+        if (!CRM_Case_BAO_Case::buildOptions($key, 'create')) {
+          CRM_Core_Error::fatal(ts('You do not have any active %1', array(1 => $label)));
         }
       }
     }
@@ -179,15 +176,10 @@ class CRM_Case_Form_Case extends CRM_Core_Form {
     $className::preProcess($this);
     $activityGroupTree = $this->_groupTree;
 
-    if (!$this->_caseTypeId) {
-      $params = CRM_Utils_Request::exportValues();
-      if (isset($params['case_type_id'])) {
-        $this->_caseTypeId = $params['case_type_id'];
-      }
-    }
     // for case custom fields to populate with defaults
     if (!empty($_POST['hidden_custom'])) {
-      CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_caseTypeId, 1, 'Case', $this->_caseId);
+      $params = CRM_Utils_Request::exportValues();
+      CRM_Custom_Form_CustomData::preProcess($this, NULL, CRM_Utils_Array::value('case_type_id', $params, $this->_caseTypeId), 1, 'Case', $this->_caseId);
       CRM_Custom_Form_CustomData::buildQuickForm($this);
     }
 
@@ -252,12 +244,11 @@ class CRM_Case_Form_Case extends CRM_Core_Form {
       )), TRUE
     );
 
-    CRM_Core_BAO_Tag::getTags('civicrm_case', $tags, NULL,
-      '  ', TRUE);
+    $tags = CRM_Core_BAO_Tag::getColorTags('civicrm_case');
 
     if (!empty($tags)) {
-      $this->add('select', 'tag', ts('Select Tags'), $tags, FALSE,
-        array('id' => 'tags', 'multiple' => 'multiple', 'class' => 'crm-select2')
+      $this->add('select2', 'tag', ts('Tags'), $tags, FALSE,
+        array('class' => 'huge', 'multiple' => 'multiple')
       );
     }
 
@@ -379,6 +370,9 @@ class CRM_Case_Form_Case extends CRM_Core_Form {
     $tagParams = array();
     if (!empty($params['tag'])) {
       $tagParams = array();
+      if (!is_array($params['tag'])) {
+        $params['tag'] = explode(',', $params['tag']);
+      }
       foreach ($params['tag'] as $tag) {
         $tagParams[$tag] = 1;
       }