Add support for email & contact_tags in url
authoreileen <emcnaughton@wikimedia.org>
Tue, 30 Jul 2019 08:02:27 +0000 (20:02 +1200)
committereileen <emcnaughton@wikimedia.org>
Fri, 2 Aug 2019 21:09:25 +0000 (09:09 +1200)
CRM/Contact/Form/Search/Advanced.php
CRM/Contact/Form/Search/Criteria.php
CRM/Core/Form/Search.php

index 572e447e65ced6d26c57692550dd3a52f851c65f..0fcb3e73641045739a08c4d89cd7ab2f0db4a805 100644 (file)
@@ -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]";
index 0532894df383ff8e39050db269bee1a27348e594..2d5695b78d03bdf6be3d113a1cd627c89a475b3f 100644 (file)
@@ -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) {
index eeaf1798b437170cbab4f3c3771c584552a6f364..1ade998abd75526e593bab89aff9b11a45e1643f 100644 (file)
@@ -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'];
           }