Skip to content

Commit

Permalink
Convert sort_name to use search form methodology to pass by url
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jun 7, 2019
1 parent 4741274 commit d88e84c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
10 changes: 0 additions & 10 deletions CRM/Activity/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,16 +353,6 @@ public function getFormValues() {
return NULL;
}

/**
* This virtual function is used to set the default values of various form elements.
*
* @return array|NULL
* reference to the array of default values
*/
public function setDefaultValues() {
return array_merge($this->getEntityDefaults($this->getDefaultEntity()), (array) $this->_formValues);
}

/**
* Return a descriptive name for the page, used in wizard header
*
Expand Down
8 changes: 4 additions & 4 deletions CRM/Contact/Form/Search/Advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,26 +190,26 @@ public function getTemplateFileName() {
/**
* Set the default form values.
*
*
* @return array
* the default array reference
* @throws \Exception
*/
public function setDefaultValues() {
$defaults = parent::setDefaultValues();
// Set ssID for unit tests.
if (empty($this->_ssID)) {
$this->_ssID = $this->get('ssID');
}

$defaults = array_merge($this->_formValues, array(
$defaults = array_merge($this->_formValues, [
'privacy_toggle' => 1,
'operator' => 'AND',
));
], $defaults);
$this->normalizeDefaultValues($defaults);

if ($this->_context === 'amtg') {
$defaults['task'] = CRM_Contact_Task::GROUP_ADD;
}

return $defaults;
}

Expand Down
23 changes: 19 additions & 4 deletions CRM/Contact/Form/Search/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@
class CRM_Contact_Form_Search_Criteria {

/**
* @param CRM_Core_Form $form
* @param CRM_Contact_Form_Search_Advanced $form
*
* @throws \CRM_Core_Exception
*/
public static function basic(&$form) {
$form->addSearchFieldMetadata(['Contact' => self::getSearchFieldMetadata()]);
$form->addFormFieldsFromMetadata();
self::setBasicSearchFields($form);
$form->addElement('hidden', 'hidden_basic', 1);

Expand Down Expand Up @@ -100,9 +104,6 @@ public static function basic(&$form) {
}
}

// add text box for last name, first name, street name, city
$form->addElement('text', 'sort_name', ts('Complete OR Partial Name'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));

// 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'));

Expand Down Expand Up @@ -254,6 +255,20 @@ public static function basic(&$form) {
$form->add('select', 'phone_phone_type_id', ts('Phone Type'), ['' => ts('- any -')] + $phoneType, FALSE, ['class' => 'crm-select2']);
}

/**
* Get the metadata for fields to be included on the contact search form.
*/
public static function getSearchFieldMetadata() {
$fields = [
'sort_name' => ['title' => ts('Complete OR Partial Name'), 'template_grouping' => 'basic'],
];
$metadata = civicrm_api3('Contact', 'getfields', [])['values'];
foreach ($fields as $fieldName => $field) {
$fields[$fieldName] = array_merge(CRM_Utils_Array::value($fieldName, $metadata, []), $field);
}
return $fields;
}

/**
* Defines the fields that can be displayed for the basic search section.
*
Expand Down
17 changes: 16 additions & 1 deletion CRM/Core/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,17 @@ public function addSearchFieldMetadata($searchFieldMetadata) {
$this->searchFieldMetadata = array_merge($this->searchFieldMetadata, $searchFieldMetadata);
}

/**
* This virtual function is used to set the default values of various form elements.
*
* @return array|NULL
* reference to the array of default values
* @throws \Exception
*/
public function setDefaultValues() {
return array_merge($this->getEntityDefaults($this->getDefaultEntity()), (array) $this->_formValues);
}

/**
* Common buildForm tasks required by all searches.
*/
Expand Down Expand Up @@ -159,7 +170,11 @@ public function addFormFieldsFromMetadata() {
$this->addDatePickerRange($fieldName, $fieldSpec['title'], ($fieldSpec['type'] === (CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME)));
}
else {
$this->addField($fieldName, ['entity' => $entity]);
$props = ['entity' => $entity];
if (isset($fields[$fieldName]['title'])) {
$props['label'] = $fields[$fieldName]['title'];
}
$this->addField($fieldName, $props);
}
}
}
Expand Down

0 comments on commit d88e84c

Please sign in to comment.