Merge pull request #9894 from JKingsnorth/CRM-20175
[civicrm-core.git] / CRM / Utils / Type.php
index c782e5cec5a6c8574bba69db091b1d3bdb82271d..65b726c98f04b7353ed46b90b424d2060dba5aec 100644 (file)
@@ -143,6 +143,28 @@ class CRM_Utils_Type {
     return (isset($string)) ? $string : "";
   }
 
+  /**
+   * Get the data_type for the field.
+   *
+   * @param array $fieldMetadata
+   *   Metadata about the field.
+   *
+   * @return string
+   */
+  public static function getDataTypeFromFieldMetadata($fieldMetadata) {
+    if (isset($fieldMetadata['data_type'])) {
+      return $fieldMetadata['data_type'];
+    }
+    if (empty($fieldMetadata['type'])) {
+      // I would prefer to throw an e-notice but there is some,
+      // probably unnecessary logic, that only retrieves activity fields
+      // if they are 'in the profile' and probably they are not 'in'
+      // until they are added - which might lead to ? who knows!
+      return '';
+    }
+    return self::typeToString($fieldMetadata['type']);
+  }
+
   /**
    * Helper function to call escape on arrays.
    *