$defaults = [];
$mapperKeys = array_keys($this->_mapperFields);
$hasColumnNames = !empty($this->_columnNames);
- $hasLocationTypes = $this->get('fieldTypes');
$this->_location_types = ['Primary' => ts('Primary')] + CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
$defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
$values = [];
foreach ($relatedFields as $name => $field) {
$values[$name] = $field['title'];
- if (isset($hasLocationTypes[$name])) {
+ if ($this->isLocationTypeRequired($name)) {
$sel3[$key][$name] = $this->_location_types;
}
elseif ($name === 'url') {
}
else {
$options = NULL;
- if (!empty($hasLocationTypes[$key])) {
+ if ($this->isLocationTypeRequired($key)) {
$options = $this->_location_types;
}
elseif ($key === 'url') {
return $highlightedFields;
}
+ /**
+ * Get an array of fields with TRUE or FALSE to reflect need for location type.
+ *
+ * e.g ['first_name' => FALSE, 'email' => TRUE, 'street_address' => TRUE']
+ *
+ * @return bool
+ */
+ private function isLocationTypeRequired($name): bool {
+ if (!isset(Civi::$statics[__CLASS__]['location_fields'])) {
+ Civi::$statics[__CLASS__]['location_fields'] = (new CRM_Contact_Import_Parser_Contact())->setUserJobID($this->getUserJobID())->getSelectTypes();
+ }
+ return (bool) (Civi::$statics[__CLASS__]['location_fields'][$name] ?? FALSE);
+ }
+
}
* Set user job ID.
*
* @param int $userJobID
+ *
+ * @return self
*/
- public function setUserJobID(int $userJobID): void {
+ public function setUserJobID(int $userJobID): self {
$this->userJobID = $userJobID;
+ return $this;
}
/**
*/
public function getSelectTypes() {
$values = [];
+ // This is only called from the MapField form in isolation now,
+ // so we need to set the metadata.
+ $this->init();
foreach ($this->_fields as $name => $field) {
if (isset($field->_hasLocationType)) {
$values[$name] = $field->_hasLocationType;