From d7cc9ca9579ba5a28f346d114b3db7d0feb619bd Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 30 Jul 2019 20:02:27 +1200 Subject: [PATCH] Add support for email & contact_tags in url --- CRM/Contact/Form/Search/Advanced.php | 2 +- CRM/Contact/Form/Search/Criteria.php | 7 ++++--- CRM/Core/Form/Search.php | 11 ++++++++--- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CRM/Contact/Form/Search/Advanced.php b/CRM/Contact/Form/Search/Advanced.php index 572e447e65..0fcb3e7364 100644 --- a/CRM/Contact/Form/Search/Advanced.php +++ b/CRM/Contact/Form/Search/Advanced.php @@ -402,7 +402,7 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search { * id of the tagset. */ if (isset($defaults['contact_tags'])) { - foreach ($defaults['contact_tags'] as $key => $tagId) { + foreach ((array) $defaults['contact_tags'] as $key => $tagId) { if (!is_array($tagId)) { $parentId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $tagId, 'parent_id'); $element = "contact_taglist[$parentId]"; diff --git a/CRM/Contact/Form/Search/Criteria.php b/CRM/Contact/Form/Search/Criteria.php index 0532894df3..2d5695b78d 100644 --- a/CRM/Contact/Form/Search/Criteria.php +++ b/CRM/Contact/Form/Search/Criteria.php @@ -104,9 +104,6 @@ class CRM_Contact_Form_Search_Criteria { } } - // add text box for last name, first name, street name, city - $form->add('text', 'email', ts('Complete OR Partial Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); - //added contact source $form->add('text', 'contact_source', ts('Contact Source'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'contact_source')); @@ -257,10 +254,14 @@ class CRM_Contact_Form_Search_Criteria { /** * Get the metadata for fields to be included on the contact search form. + * + * @throws \CiviCRM_API3_Exception */ public static function getSearchFieldMetadata() { $fields = [ 'sort_name' => ['title' => ts('Complete OR Partial Name'), 'template_grouping' => 'basic'], + 'email' => ['title' => ts('Complete OR Partial Email'), 'entity' => 'Email', 'template_grouping' => 'basic'], + 'contact_tags' => ['name' => 'contact_tags', 'type' => CRM_Utils_Type::T_INT, 'is_pseudofield' => TRUE, 'template_grouping' => 'basic'], ]; $metadata = civicrm_api3('Contact', 'getfields', [])['values']; foreach ($fields as $fieldName => $field) { diff --git a/CRM/Core/Form/Search.php b/CRM/Core/Form/Search.php index eeaf1798b4..1ade998abd 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -187,12 +187,17 @@ class CRM_Core_Form_Search extends CRM_Core_Form { $this->_action = CRM_Core_Action::ADVANCED; foreach ($this->getSearchFieldMetadata() as $entity => $fields) { foreach ($fields as $fieldName => $fieldSpec) { - if ($fieldSpec['type'] === CRM_Utils_Type::T_DATE || $fieldSpec['type'] === (CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME)) { + $fieldType = $fieldSpec['type'] ?? ''; + if ($fieldType === CRM_Utils_Type::T_DATE || $fieldType === (CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME)) { $title = empty($fieldSpec['unique_title']) ? $fieldSpec['title'] : $fieldSpec['unique_title']; - $this->addDatePickerRange($fieldName, $title, ($fieldSpec['type'] === (CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME))); + $this->addDatePickerRange($fieldName, $title, ($fieldType === (CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME))); } else { - $props = ['entity' => $entity]; + // Not quite sure about moving to a mix of keying by entity vs permitting entity to + // be passed in. The challenge of the former is that it doesn't permit ordering. + // Perhaps keying was the wrong starting point & we should do a flat array as all + // fields eventually need to be unique. + $props = ['entity' => $fieldSpec['entity'] ?? $entity]; if (isset($fields[$fieldName]['unique_title'])) { $props['label'] = $fields[$fieldName]['unique_title']; } -- 2.25.1