Merge pull request #4708 from jitendrapurohit/CRM-15662
[civicrm-core.git] / CRM / Contact / Import / Form / MapField.php
index 03ef69cc9352b683f3a35d141d9f10fb23850ca9..a97805064b2036c193000e10ddfe1f4d720c3919 100644 (file)
@@ -57,6 +57,8 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField {
 
   protected $_dedupeFields;
 
+  protected static $customFields;
+
   /**
    * Attempt to match header labels with our mapper fields
    * FIXME: This is essentially the same function as parent::defaultFromHeader
@@ -151,9 +153,16 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField {
         }
       }
     }
-
+    // retrieve and highlight required custom fields
+    $formattedFieldNames = $this->formatCustomFieldName($this->_mapperFields);
+    self::$customFields = CRM_Core_BAO_CustomField::getFields($this->_contactType);
+    foreach(self::$customFields as $key => $attr) {
+      if (!empty($attr['is_required'])) {
+        $highlightedFields[] = "custom_$key";
+      }
+    }
     $this->assign('highlightedFields', $highlightedFields);
-    $this->_formattedFieldNames[$contactType] = $this->_mapperFields = array_merge($this->_mapperFields, $this->formatCustomFieldName($this->_mapperFields));
+    $this->_formattedFieldNames[$contactType] = $this->_mapperFields = array_merge($this->_mapperFields, $formattedFieldNames);
 
     $columnNames = array();
     //get original col headers from csv if present.
@@ -971,6 +980,8 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField {
    * format custom field name.
    * combine group and field name to avoid conflict.
    *
+   * @param $fields
+   *
    * @return void
    * @access public
    */