* 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]";
}
}
- // 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'));
/**
* 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) {
$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'];
}