Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove last usage of _fields from Import_Parser #24273

Merged
merged 3 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CRM/Contact/Import/Form/MapField.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ protected function getHighlightedFields(): array {
*/
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();
Civi::$statics[__CLASS__]['location_fields'] = (new CRM_Contact_Import_Parser_Contact())->setUserJobID($this->getUserJobID())->getFieldsWhichSupportLocationTypes();
}
return (bool) (Civi::$statics[__CLASS__]['location_fields'][$name] ?? FALSE);
}
Expand Down
29 changes: 22 additions & 7 deletions CRM/Import/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,13 @@ public function getContactSubType(): ?string {
protected $_warnings;

/**
* TO BE REMOVED.
*
* Array of all the fields that could potentially be part
* of this import process
* @var array
*/
protected $_fields;
private $_fields;

/**
* Metadata for all available fields, keyed by unique name.
Expand Down Expand Up @@ -491,16 +493,16 @@ public function progressImport($statusID, $startImport = TRUE, $startTimestamp =
}

/**
* Get an array of available fields that support location types (e.g phone, street_address etc).
*
* @return array
*/
public function getSelectTypes() {
public function getFieldsWhichSupportLocationTypes(): array {
$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;
foreach ($this->getFieldsMetadata() as $name => $field) {
if (isset($field['hasLocationType'])) {
$values[$name] = TRUE;
}
}
return $values;
Expand Down Expand Up @@ -1801,6 +1803,19 @@ public function init() {
$this->setFieldMetadata();
}

/**
* Get metadata for all importable fields.
*
* @return array
*/
protected function getFieldsMetadata() : array {
if (empty($this->importableFieldsMetadata)) {
unset($this->userJob);
$this->setFieldMetadata();
}
return $this->importableFieldsMetadata;
}

/**
* @param array $mappedField
* Field detail as would be saved in field_mapping table
Expand Down