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
*
/**
* 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;
}
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);
}
}
- // 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'));
$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.
*
/**
* Metadata for fields on the search form.
*
+ * Instantiate with empty array for contact to prevent e-notices.
+ *
* @var array
*/
- protected $searchFieldMetadata = [];
+ protected $searchFieldMetadata = ['Contact' => []];
/**
* @return array
$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.
*/
$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);
}
}
}