Merge pull request #4997 from monishdeb/CRM-15536
[civicrm-core.git] / CRM / Core / BAO / CustomField.php
index fb78197550aea9614ca4968bd7858d30b237edc1..c923c542ac2e567ba1d85f50af457f11af4810d6 100644 (file)
@@ -23,7 +23,7 @@
   | GNU Affero General Public License or the licensing of CiviCRM,     |
   | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
   +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
@@ -43,7 +43,6 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
    * Array for valid combinations of data_type & descriptions
    *
    * @var array
-   * @static
    */
   public static $_dataType = NULL;
 
@@ -51,7 +50,6 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
    * Array for valid combinations of data_type & html_type
    *
    * @var array
-   * @static
    */
   public static $_dataToHtml = NULL;
 
@@ -59,17 +57,14 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
    * Array to hold (formatted) fields for import
    *
    * @var array
-   * @static
    */
   public static $_importFields = NULL;
 
   /**
    * Build and retrieve the list of data types and descriptions
    *
-   * @param NULL
-   *
-   * @return array        Data type => Description
-   * @static
+   * @return array
+   *   Data type => Description
    */
   public static function &dataType() {
     if (!(self::$_dataType)) {
@@ -98,8 +93,10 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
     if (!self::$_dataToHtml) {
       self::$_dataToHtml = array(
         array(
-          'Text' => 'Text', 'Select' => 'Select',
-          'Radio' => 'Radio', 'CheckBox' => 'CheckBox',
+          'Text' => 'Text',
+          'Select' => 'Select',
+          'Radio' => 'Radio',
+          'CheckBox' => 'CheckBox',
           'Multi-Select' => 'Multi-Select',
           'AdvMulti-Select' => 'AdvMulti-Select',
           'Autocomplete-Select' => 'Autocomplete-Select',
@@ -128,8 +125,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
    * @param array $params
    *   (reference) an assoc array of name/value pairs.
    *
-   * @return CRM_Core_DAO_CustomField object
-   * @static
+   * @return CRM_Core_DAO_CustomField
    */
   public static function create(&$params) {
     $origParams = array_merge(array(), $params);
@@ -157,13 +153,14 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
       $indexExist = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'is_searchable');
     }
 
-    switch (CRM_Utils_Array::value('html_type', $params)){
+    switch (CRM_Utils_Array::value('html_type', $params)) {
       case 'Select Date':
-        if(empty($params['date_format'])){
+        if (empty($params['date_format'])) {
           $config = CRM_Core_Config::singleton();
           $params['date_format'] = $config->dateInputFormat;
         }
         break;
+
       case 'CheckBox':
       case 'AdvMulti-Select':
       case 'Multi-Select':
@@ -187,14 +184,18 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
             $params['default_value'] = $params['option_value'][$params['default_option']];
           }
         }
-       break;
+        break;
     }
 
     $transaction = new CRM_Core_Transaction();
     // create any option group & values if required
     if ($params['html_type'] != 'Text' &&
       in_array($params['data_type'], array(
-        'String', 'Int', 'Float', 'Money'))
+        'String',
+        'Int',
+        'Float',
+        'Money',
+      ))
     ) {
 
       $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup',
@@ -202,7 +203,6 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
         'table_name'
       );
 
-
       if ($params['option_type'] == 1 && empty($params['option_group_id'])) {
         // first create an option group for this custom group
         $optionGroup = new CRM_Core_DAO_OptionGroup();
@@ -211,7 +211,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
         $optionGroup->is_active = 1;
         $optionGroup->save();
         $params['option_group_id'] = $optionGroup->id;
-          if(!empty($params['option_value']) && is_array($params['option_value'])){
+        if (!empty($params['option_value']) && is_array($params['option_value'])) {
           foreach ($params['option_value'] as $k => $v) {
             if (strlen(trim($v))) {
               $optionValue = new CRM_Core_DAO_OptionValue();
@@ -259,8 +259,9 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
         );
 
         if (!CRM_Utils_System::isNull(explode(CRM_Core_DAO::VALUE_SEPARATOR,
-              $defaultValue
-            ))) {
+          $defaultValue
+        ))
+        ) {
           $params['default_value'] = $defaultValue;
         }
       }
@@ -319,8 +320,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
    * @param array $defaults
    *   (reference ) an assoc array to hold the flattened values.
    *
-   * @return CRM_Core_DAO_CustomField object
-   * @static
+   * @return CRM_Core_DAO_CustomField
    */
   public static function retrieve(&$params, &$defaults) {
     return CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $defaults);
@@ -334,9 +334,9 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
    * @param bool $is_active
    *   Value we want to set the is_active field.
    *
-   * @return   Object            DAO object on sucess, null otherwise
+   * @return Object
+   *   DAO object on sucess, null otherwise
    *
-   * @static
    */
   public static function setIsActive($id, $is_active) {
 
@@ -353,9 +353,8 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
    * @param int $id
    *   Id of field.
    *
-   * @return string name
-   *
-   * @static
+   * @return string
+   *   name
    *
    */
   public static function getTitle($id) {
@@ -382,18 +381,19 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
    * @param bool $checkPermission
    *   If false, do not include permissioning clause.
    *
-   * @return array      $fields - an array of active custom fields.
+   * @return array
+   *   an array of active custom fields.
    *
-   * @static
    */
-  public static function &getFields($customDataType = 'Individual',
-                                    $showAll = FALSE,
-                                    $inline = FALSE,
-                                    $customDataSubType = NULL,
-                                    $customDataSubName = NULL,
-                                    $onlyParent = FALSE,
-                                    $onlySubType = FALSE,
-                                    $checkPermission = TRUE
+  public static function &getFields(
+    $customDataType = 'Individual',
+    $showAll = FALSE,
+    $inline = FALSE,
+    $customDataSubType = NULL,
+    $customDataSubName = NULL,
+    $onlyParent = FALSE,
+    $onlySubType = FALSE,
+    $checkPermission = TRUE
   ) {
     if (empty($customDataType)) {
       $customDataType = array('Contact', 'Individual', 'Organization', 'Household');
@@ -604,16 +604,17 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
    *
    * @param bool $withMultiple
    *
-   * @return array   $fields -
+   * @return array
+   *
    *
-   * @static
    */
-  public static function &getFieldsForImport($contactType = 'Individual',
-    $showAll         = FALSE,
-    $onlyParent      = FALSE,
-    $search          = FALSE,
+  public static function &getFieldsForImport(
+    $contactType = 'Individual',
+    $showAll = FALSE,
+    $onlyParent = FALSE,
+    $search = FALSE,
     $checkPermission = TRUE,
-    $withMultiple    = FALSE
+    $withMultiple = FALSE
   ) {
     // Note: there are situations when we want getFieldsForImport() return fields related
     // ONLY to basic contact types, but NOT subtypes. And thats where $onlyParent is helpful
@@ -671,8 +672,8 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
    *   The key to parse.
    *
    * @param bool $all
-   * @return int|null         The id (if exists)
-   * @static
+   * @return int|null
+   *   The id (if exists)
    */
   public static function getKeyID($key, $all = FALSE) {
     $match = array();
@@ -696,16 +697,15 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
    * @param int $fieldID
    *   The custom field ID.
    *
-   * @return CRM_Core_DAO_CustomField $field  the field object
-   * @static
-   * public
+   * @return CRM_Core_DAO_CustomField
+   *   The field object.
    */
   public static function getFieldObject($fieldID) {
     $field = new CRM_Core_DAO_CustomField();
 
     // check if we can get the field values from the system cache
-    $cacheKey    = "CRM_Core_DAO_CustomField_{$fieldID}";
-    $cache       = CRM_Utils_Cache::singleton();
+    $cacheKey = "CRM_Core_DAO_CustomField_{$fieldID}";
+    $cache = CRM_Utils_Cache::singleton();
     $fieldValues = $cache->get($cacheKey);
     if (empty($fieldValues)) {
       $field->id = $fieldID;
@@ -742,23 +742,23 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
    * @param string $label
    *   Label for custom field.
    *
-   * @static
    */
-  public static function addQuickFormElement(&$qf,
+  public static function addQuickFormElement(
+    &$qf,
     $elementName,
     $fieldId,
     $inactiveNeeded = FALSE,
-    $useRequired    = TRUE,
-    $search         = FALSE,
-    $label          = NULL
+    $useRequired = TRUE,
+    $search = FALSE,
+    $label = NULL
   ) {
     $field = self::getFieldObject($fieldId);
     $widget = $field->html_type;
 
     // Custom field HTML should indicate group+field name
     $groupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $field->custom_group_id);
-    $dataCrmCustomVal = $groupName.':'.$field->name;
-    $dataCrmCustomAttr = 'data-crm-custom="'.$dataCrmCustomVal.'"';
+    $dataCrmCustomVal = $groupName . ':' . $field->name;
+    $dataCrmCustomAttr = 'data-crm-custom="' . $dataCrmCustomVal . '"';
     $field->attributes .= $dataCrmCustomAttr;
 
     // Fixed for Issue CRM-2183
@@ -769,10 +769,23 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
     $placeholder = $search ? ts('- any -') : ($useRequired ? ts('- select -') : ts('- none -'));
 
     // FIXME: Why are select state/country separate widget types?
-    $isSelect = (in_array($widget, array('Select', 'Multi-Select', 'Select State/Province', 'Multi-Select State/Province', 'Select Country', 'Multi-Select Country', 'AdvMulti-Select', 'CheckBox', 'Radio')));
+    $isSelect = (in_array($widget, array(
+      'Select',
+      'Multi-Select',
+      'Select State/Province',
+      'Multi-Select State/Province',
+      'Select Country',
+      'Multi-Select Country',
+      'AdvMulti-Select',
+      'CheckBox',
+      'Radio',
+    )));
 
     if ($isSelect) {
-      $options = CRM_Utils_Array::value('values', civicrm_api3('contact', 'getoptions', array('field' => "custom_$fieldId", 'context' => $search ? 'search' : 'create'), array()));
+      $options = CRM_Utils_Array::value('values', civicrm_api3('contact', 'getoptions', array(
+        'field' => "custom_$fieldId",
+        'context' => $search ? 'search' : 'create',
+      ), array()));
 
       // Consolidate widget types to simplify the below switch statement
       if ($search || ($widget !== 'AdvMulti-Select' && strpos($widget, 'Select') !== FALSE)) {
@@ -791,7 +804,8 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
       // Add data for popup link. Normally this is handled by CRM_Core_Form->addSelect
       if ($field->option_group_id && !$search && $widget == 'Select' && CRM_Core_Permission::check('administer CiviCRM')) {
         $selectAttributes += array(
-          'data-api-entity' => 'contact', // FIXME: This works because the getoptions api isn't picky about custom fields, but it's WRONG
+          'data-api-entity' => 'contact',
+          // FIXME: This works because the getoptions api isn't picky about custom fields, but it's WRONG
           'data-api-field' => 'custom_' . $field->id,
           'data-option-edit-path' => 'civicrm/admin/options/' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $field->option_group_id),
         );
@@ -873,18 +887,18 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
 
           $qf->addDate($elementName, $label, $required, array(
             'format' => $field->date_format,
-              'timeFormat' => $field->time_format,
-              'startOffset' => $field->start_date_years,
-              'endOffset' => $field->end_date_years,
-              'data-crm-custom' => $dataCrmCustomVal,
-            ));
+            'timeFormat' => $field->time_format,
+            'startOffset' => $field->start_date_years,
+            'endOffset' => $field->end_date_years,
+            'data-crm-custom' => $dataCrmCustomVal,
+          ));
         }
         break;
 
       case 'Radio':
         $choice = array();
         foreach ($options as $v => $l) {
-          $choice[] = $qf->createElement('radio', NULL, '', $l, (string)$v, $field->attributes);
+          $choice[] = $qf->createElement('radio', NULL, '', $l, (string) $v, $field->attributes);
         }
         $group = $qf->addGroup($choice, $elementName, $label);
         if ($useRequired && !$search) {
@@ -962,7 +976,11 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
         break;
 
       case 'RichTextEditor':
-        $attributes = array('rows' => $field->note_rows, 'cols' => $field->note_columns, 'data-crm-custom' => $dataCrmCustomVal);
+        $attributes = array(
+          'rows' => $field->note_rows,
+          'cols' => $field->note_columns,
+          'data-crm-custom' => $dataCrmCustomVal,
+        );
         if ($field->text_length) {
           $attributes['maxlength'] = $field->text_length;
         }
@@ -974,7 +992,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
         // Fixme: why is this a string in the first place??
         $attributes = array();
         if ($field->attributes) {
-          foreach(explode(' ', $field->attributes) as $at) {
+          foreach (explode(' ', $field->attributes) as $at) {
             if (strpos($at, '=')) {
               list($k, $v) = explode('=', $at);
               $attributes[$k] = trim($v, ' "');
@@ -1062,11 +1080,6 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
    *
    * @param object $field
    *   The field object.
-   *
-   * @return  boolean
-   *
-   * @static
-   *
    */
   public static function deleteField($field) {
     CRM_Utils_System::flushCache();
@@ -1084,8 +1097,6 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
     $field->delete();
     CRM_Core_BAO_UFField::delUFField($field->id);
     CRM_Utils_Weight::correctDuplicateWeights('CRM_Core_DAO_CustomField');
-
-    return;
   }
 
   /**
@@ -1102,16 +1113,16 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
    * @param int $contactID
    * @param int $fieldID
    *
-   * @return  string   the display value
+   * @return string
+   *   the display value
    *
-   * @static
    */
   public static function getDisplayValue($value, $id, &$options, $contactID = NULL, $fieldID = NULL) {
-    $option     = &$options[$id];
+    $option = &$options[$id];
     $attributes = &$option['attributes'];
-    $html_type  = $attributes['html_type'];
-    $data_type  = $attributes['data_type'];
-    $format     = CRM_Utils_Array::value('format', $attributes);
+    $html_type = $attributes['html_type'];
+    $data_type = $attributes['data_type'];
+    $format = CRM_Utils_Array::value('format', $attributes);
 
     return self::getDisplayValueCommon($value,
       $option,
@@ -1134,13 +1145,14 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
    *
    * @return array|mixed|null|string
    */
-  static function getDisplayValueCommon($value,
+  public static function getDisplayValueCommon(
+    $value,
     &$option,
     $html_type,
     $data_type,
-    $format    = NULL,
+    $format = NULL,
     $contactID = NULL,
-    $fieldID   = NULL
+    $fieldID = NULL
   ) {
     $display = $value;
 
@@ -1164,7 +1176,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
           if ($value) {
             $display = ts('Yes');
           }
-          elseif ((string)$value === '0') {
+          elseif ((string) $value === '0') {
             $display = ts('No');
           }
         }
@@ -1345,9 +1357,9 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
    *   If passed - dont fetch value from db,.
    *                               just format the given value
    *
-   * @static
    */
-  static function setProfileDefaults($customFieldId,
+  public static function setProfileDefaults(
+    $customFieldId,
     $elementName,
     &$defaults,
     $contactId = NULL,
@@ -1366,8 +1378,8 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
     }
     else {
       if (!isset($value)) {
-        $info   = self::getTableColumnGroup($customFieldId);
-        $query  = "SELECT {$info[0]}.{$info[1]} as value FROM {$info[0]} WHERE {$info[0]}.entity_id = {$contactId}";
+        $info = self::getTableColumnGroup($customFieldId);
+        $query = "SELECT {$info[0]}.{$info[1]} as value FROM {$info[0]} WHERE {$info[0]}.entity_id = {$contactId}";
         $result = CRM_Core_DAO::executeQuery($query);
         if ($result->fetch()) {
           $value = $result->value;
@@ -1557,15 +1569,16 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
    * @param bool $includeViewOnly
    *   If true, fields marked 'View Only' are included. Required for APIv3.
    *
-   * @return array $customFormatted formatted custom field array
-   * @static
+   * @return array|NULL
+   *   formatted custom field array
    */
-  static function formatCustomField($customFieldId, &$customFormatted, $value,
+  public static function formatCustomField(
+    $customFieldId, &$customFormatted, $value,
     $customFieldExtend, $customValueId = NULL,
     $entityId = NULL,
     $inline = FALSE,
     $checkPermission = TRUE,
-    $includeViewOnly = false
+    $includeViewOnly = FALSE
   ) {
     //get the custom fields for the entity
     //subtype and basic type
@@ -1575,8 +1588,8 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
     }
 
     if (in_array($customFieldExtend,
-        CRM_Contact_BAO_ContactType::subTypes()
-      )) {
+      CRM_Contact_BAO_ContactType::subTypes()
+    )) {
       // This is the case when getFieldsForImport() requires fields
       // of subtype and its parent.CRM-5143
       $customDataSubType = $customFieldExtend;
@@ -1594,12 +1607,12 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
     );
 
     if (!array_key_exists($customFieldId, $customFields)) {
-      return;
+      return NULL;
     }
 
     // return if field is a 'code' field
     if (!$includeViewOnly && !empty($customFields[$customFieldId]['is_view'])) {
-      return;
+      return NULL;
     }
 
     list($tableName, $columnName, $groupID) = self::getTableColumnGroup($customFieldId);
@@ -1630,8 +1643,8 @@ SELECT id
           }
           if (!empty($selectedValues)) {
             $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,
-              $selectedValues
-            ) . CRM_Core_DAO::VALUE_SEPARATOR;
+                $selectedValues
+              ) . CRM_Core_DAO::VALUE_SEPARATOR;
           }
           else {
             $value = '';
@@ -1648,8 +1661,8 @@ SELECT id
         // and you can directly use value, CRM-4385
         if (is_array($value)) {
           $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,
-            array_values($value)
-          ) . CRM_Core_DAO::VALUE_SEPARATOR;
+              array_values($value)
+            ) . CRM_Core_DAO::VALUE_SEPARATOR;
         }
       }
       else {
@@ -1904,8 +1917,8 @@ SELECT $columnName
    * @param int $newGroupID
    *   FK to civicrm_custom_group.
    *
-   * @return array(
-     string) or TRUE
+   * @return array
+   *   array(string) or TRUE
    */
   public static function _moveFieldValidate($fieldID, $newGroupID) {
     $errors = array();
@@ -1965,7 +1978,8 @@ SELECT extends
 FROM   civicrm_custom_group
 WHERE  id IN ( %1, %2 )
 ";
-      $params = array(1 => array($oldGroup->id, 'Integer'),
+      $params = array(
+        1 => array($oldGroup->id, 'Integer'),
         2 => array($newGroup->id, 'Integer'),
       );
 
@@ -2036,12 +2050,12 @@ WHERE  id IN ( %1, %2 )
    * @param bool $force
    *   Force the sql to be run again (primarily used for tests).
    *
-   * @return array           - fatal is fieldID does not exists, else array of tableName, columnName
-   * @static
+   * @return array
+   *   fatal is fieldID does not exists, else array of tableName, columnName
    */
   public static function getTableColumnGroup($fieldID, $force = FALSE) {
-    $cacheKey    = "CRM_Core_DAO_CustomField_CustomGroup_TableColumn_{$fieldID}";
-    $cache       = CRM_Utils_Cache::singleton();
+    $cacheKey = "CRM_Core_DAO_CustomField_CustomGroup_TableColumn_{$fieldID}";
+    $cache = CRM_Utils_Cache::singleton();
     $fieldValues = $cache->get($cacheKey);
     if (empty($fieldValues) || $force) {
       $query = "
@@ -2068,13 +2082,13 @@ AND    cf.id = %1";
    *
    * @param array $includeFieldIds
    *   Ids of custom fields for which.
-   * option groups must be included.
+   *   option groups must be included.
    *
    * Currently this is required in the cases where option groups are to be included
    * for inactive fields : CRM-5369
    *
    *
-   * @return mixed $customOptionGroup@static
+   * @return mixed
    */
   public static function &customOptionGroup($includeFieldIds = NULL) {
     static $customOptionGroup = NULL;
@@ -2119,7 +2133,6 @@ INNER JOIN  civicrm_custom_field f ON ( g.id = f.option_group_id )
    *   Option group id.
    *
    * @return void
-   * @static
    */
   public static function fixOptionGroups($customFieldId, $optionGroupId) {
     // check if option group belongs to any custom Field else delete
@@ -2146,7 +2159,6 @@ INNER JOIN  civicrm_custom_field f ON ( g.id = f.option_group_id )
    *   Option group id.
    *
    * @return void
-   * @static
    */
   public static function checkOptionGroup($optionGroupId) {
     $query = "
@@ -2176,8 +2188,8 @@ WHERE    option_group_id = {$optionGroupId}
 AND      default_value IS NOT NULL
 ORDER BY html_type";
 
-    $dao             = CRM_Core_DAO::executeQuery($query);
-    $defaultValue    = NULL;
+    $dao = CRM_Core_DAO::executeQuery($query);
+    $defaultValue = NULL;
     $defaultHTMLType = NULL;
     while ($dao->fetch()) {
       if ($dao->html_type == $htmlType) {
@@ -2218,7 +2230,8 @@ ORDER BY html_type";
    *
    * @return array
    */
-  static function postProcess(&$params,
+  public static function postProcess(
+    &$params,
     &$customFields,
     $entityID,
     $customFieldExtends,
@@ -2269,12 +2282,13 @@ ORDER BY html_type";
 
     $optionGroupID = NULL;
     if (($field['html_type'] == 'CheckBox' ||
-        $field['html_type'] == 'Radio' ||
-        $field['html_type'] == 'Select' ||
-        $field['html_type'] == 'AdvMulti-Select' ||
-        $field['html_type'] == 'Multi-Select' ||
-        ($field['html_type'] == 'Autocomplete-Select' && $field['data_type'] != 'ContactReference')
-      )) {
+      $field['html_type'] == 'Radio' ||
+      $field['html_type'] == 'Select' ||
+      $field['html_type'] == 'AdvMulti-Select' ||
+      $field['html_type'] == 'Multi-Select' ||
+      ($field['html_type'] == 'Autocomplete-Select' && $field['data_type'] != 'ContactReference')
+    )
+    ) {
       if ($field['option_group_id']) {
         $optionGroupID = $field['option_group_id'];
       }
@@ -2345,7 +2359,6 @@ WHERE      ( f.label = %1 OR f.name = %1 )
 
   /**
    * Given ID of a custom field, return its name as well as the name of the custom group it belongs to.
-   *
    */
   public static function getNameFromID($ids) {
     if (is_array($ids)) {
@@ -2357,7 +2370,6 @@ FROM       civicrm_custom_field f
 INNER JOIN civicrm_custom_group g ON f.custom_group_id = g.id
 WHERE      f.id IN ($ids)";
 
-
     $dao = CRM_Core_DAO::executeQuery($sql);
     $result = array();
     while ($dao->fetch()) {
@@ -2376,10 +2388,10 @@ WHERE      f.id IN ($ids)";
    *
    * @param array $params
    *   Custom data submitted.
-   * ie array( 'custom_1' => 'validate me' );
+   *   ie array( 'custom_1' => 'validate me' );
    *
-   * @return array $errors validation errors.
-   * @static
+   * @return array
+   *   validation errors.
    */
   public static function validateCustomData($params) {
     $errors = array();
@@ -2387,7 +2399,6 @@ WHERE      f.id IN ($ids)";
       return $errors;
     }
 
-
     //pick up profile fields.
     $profileFields = array();
     $ufGroupId = CRM_Utils_Array::value('ufGroupId', $params);
@@ -2414,8 +2425,8 @@ WHERE      f.id IN ($ids)";
       $dataType = $field->data_type;
 
       $profileField = CRM_Utils_Array::value($key, $profileFields, array());
-      $fieldTitle   = CRM_Utils_Array::value('title', $profileField);
-      $isRequired   = CRM_Utils_Array::value('is_required', $profileField);
+      $fieldTitle = CRM_Utils_Array::value('title', $profileField);
+      $isRequired = CRM_Utils_Array::value('is_required', $profileField);
       if (!$fieldTitle) {
         $fieldTitle = $field->label;
       }
@@ -2517,4 +2528,5 @@ WHERE cf.id = %1 AND cg.is_multiple = 1";
     // FIXME: Currently the only way to know if data is serialized is by looking at the html_type. It would be cleaner to decouple this.
     return ($field['html_type'] == 'CheckBox' || strpos($field['html_type'], 'Multi') !== FALSE);
   }
+
 }