-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract metadata definition into a trait.
This metadata needs to be shared between multiple import forms. They do not have a common parent. Curently this is done via calculating once & passing via quickform. However, the formats are convoluted & hard to read. Information that is user generated should be calculated per form - not so much metadata
- Loading branch information
1 parent
f39da48
commit c67a47b
Showing
2 changed files
with
66 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
/** | ||
* Trait CRM_Contact_Import_MetadataTrait | ||
* | ||
* Trait for handling contact import specific metadata so it | ||
* does not need to be passed from one form to the next. | ||
*/ | ||
trait CRM_Contact_Import_MetadataTrait { | ||
|
||
/** | ||
* Get metadata for contact importable fields. | ||
* | ||
* @return array | ||
*/ | ||
protected function getContactImportMetadata(): array { | ||
$contactFields = CRM_Contact_BAO_Contact::importableFields($this->_contactType); | ||
// exclude the address options disabled in the Address Settings | ||
$fields = CRM_Core_BAO_Address::validateAddressOptions($contactFields); | ||
|
||
//CRM-5125 | ||
//supporting import for contact subtypes | ||
$csType = NULL; | ||
if (!empty($this->_contactSubType)) { | ||
//custom fields for sub type | ||
$subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($this->_contactSubType); | ||
|
||
if (!empty($subTypeFields)) { | ||
foreach ($subTypeFields as $customSubTypeField => $details) { | ||
$fields[$customSubTypeField] = $details; | ||
} | ||
} | ||
} | ||
|
||
//Relationship importables | ||
$this->_relationships = $relations | ||
= CRM_Contact_BAO_Relationship::getContactRelationshipType( | ||
NULL, NULL, NULL, $this->_contactType, | ||
FALSE, 'label', TRUE, $this->_contactSubType | ||
); | ||
asort($relations); | ||
|
||
foreach ($relations as $key => $var) { | ||
list($type) = explode('_', $key); | ||
$relationshipType[$key]['title'] = $var; | ||
$relationshipType[$key]['headerPattern'] = '/' . preg_quote($var, '/') . '/'; | ||
$relationshipType[$key]['import'] = TRUE; | ||
$relationshipType[$key]['relationship_type_id'] = $type; | ||
$relationshipType[$key]['related'] = TRUE; | ||
} | ||
|
||
if (!empty($relationshipType)) { | ||
$fields = array_merge($fields, [ | ||
'related' => [ | ||
'title' => ts('- related contact info -'), | ||
], | ||
], $relationshipType); | ||
} | ||
return $fields; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters