Merge remote-tracking branch 'upstream/4.5' into 4.5-4.6-2015-03-16-17-24-33
[civicrm-core.git] / CRM / Core / BAO / CustomField.php
index b73b2d511414347785a1347e47c1c4b4cdcb6165..432bd3d27d0b3fa44d093e1e08be63da0bc59565 100644 (file)
@@ -1317,7 +1317,15 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
         break;
 
       case 'File':
-        if ($value) {
+        // In the context of displaying a profile, show file/image
+        if ($contactID && $value) {
+          $url = self::getFileURL($contactID, $fieldID, $value);
+          if ($url) {
+            $display = $url['file_url'];
+          }
+        }
+        // In other contexts show a paperclip icon
+        elseif ($value) {
           $icons = CRM_Core_BAO_File::paperIconAttachment('*', $value);
           $display = $icons[$value];
         }
@@ -1587,16 +1595,13 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
     //subtype and basic type
     $customDataSubType = NULL;
     if (is_array($customFieldExtend)) {
-      $customFieldExtend = $customFieldExtend[0];
-    }
-
-    if (in_array($customFieldExtend,
-      CRM_Contact_BAO_ContactType::subTypes()
-    )) {
       // This is the case when getFieldsForImport() requires fields
       // of subtype and its parent.CRM-5143
-      $customDataSubType = $customFieldExtend;
-      $customFieldExtend = CRM_Contact_BAO_ContactType::getBasicType($customDataSubType);
+      // CRM-16065 - Custom field set data not being saved if contact has more than one contact sub type
+      $customDataSubType = array_intersect(CRM_Contact_BAO_ContactType::subTypes(), (array) $customFieldExtend);
+      if (!empty($customDataSubType) && is_array($customDataSubType)) {
+        $customFieldExtend = array_unique(array_values(CRM_Contact_BAO_ContactType::getBasicType($customDataSubType)));
+      }
     }
 
     $customFields = CRM_Core_BAO_CustomField::getFields($customFieldExtend,