From b383d04305b981d187a5dd84a30534877008bd72 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 7 Jan 2020 13:25:05 -0500 Subject: [PATCH] Refactor CRM_Contact_BAO_Contact::importableFields() to use metadata This squares up the recently added metadata with a hardcoded list in the BAO, removing the hardcoded list in favor of metadata. --- CRM/Contact/BAO/Contact.php | 53 +++++----------------------------- CRM/Contact/DAO/Contact.php | 3 +- xml/schema/Contact/Contact.xml | 2 +- 3 files changed, 10 insertions(+), 48 deletions(-) diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index a392f89ac9..22f0238c64 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -1384,54 +1384,15 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); $withMultiCustomFields ) ); - //unset the fields, which are not related to their - //contact type. - $commonValues = [ - 'Individual' => [ - 'household_name', - 'legal_name', - 'sic_code', - 'organization_name', - ], - 'Household' => [ - 'first_name', - 'middle_name', - 'last_name', - 'formal_title', - 'job_title', - 'gender_id', - 'prefix_id', - 'suffix_id', - 'birth_date', - 'organization_name', - 'legal_name', - 'legal_identifier', - 'sic_code', - 'home_URL', - 'is_deceased', - 'deceased_date', - ], - 'Organization' => [ - 'first_name', - 'middle_name', - 'last_name', - 'formal_title', - 'job_title', - 'gender_id', - 'prefix_id', - 'suffix_id', - 'birth_date', - 'household_name', - 'is_deceased', - 'deceased_date', - ], - ]; - foreach ($commonValues[$contactType] as $value) { - unset($fields[$value]); + // Unset the fields which are not related to their contact type. + foreach (CRM_Contact_DAO_Contact::import() as $name => $value) { + if (!empty($value['contactType']) && $value['contactType'] !== $contactType) { + unset($fields[$name]); + } } } else { - foreach (['Individual', 'Household', 'Organization'] as $type) { + foreach (CRM_Contact_BAO_ContactType::basicTypes() as $type) { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($type, $showAll, @@ -1604,7 +1565,7 @@ WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($id, 'Integer'); ); } else { - foreach (['Individual', 'Household', 'Organization'] as $type) { + foreach (CRM_Contact_BAO_ContactType::basicTypes() as $type) { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($type, FALSE, FALSE, $search, $checkPermissions, $withMultiRecord) ); diff --git a/CRM/Contact/DAO/Contact.php b/CRM/Contact/DAO/Contact.php index 99405af76c..e4135fe7e2 100644 --- a/CRM/Contact/DAO/Contact.php +++ b/CRM/Contact/DAO/Contact.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Contact/Contact.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:773bf2fc16c1af3c283f6ecc7098e927) + * (GenCodeChecksum:4b1e2ef9f5c431f59befcc000cb35577) */ /** @@ -688,6 +688,7 @@ class CRM_Contact_DAO_Contact extends CRM_Core_DAO { 'where' => 'civicrm_contact.legal_name', 'headerPattern' => '/^legal|(l(egal\s)?name)$/i', 'export' => TRUE, + 'contactType' => 'Organization', 'table_name' => 'civicrm_contact', 'entity' => 'Contact', 'bao' => 'CRM_Contact_BAO_Contact', diff --git a/xml/schema/Contact/Contact.xml b/xml/schema/Contact/Contact.xml index 262358eaf1..28a2ee98f7 100644 --- a/xml/schema/Contact/Contact.xml +++ b/xml/schema/Contact/Contact.xml @@ -238,7 +238,7 @@ Text 30 - + Organization true /^legal|(l(egal\s)?name)$/i Legal Name. -- 2.25.1