public static function getSearchFieldMetadata() {
$fields = ['activity_type_id', 'activity_date_time', 'priority_id', 'activity_location'];
$metadata = civicrm_api3('Activity', 'getfields', [])['values'];
- return array_intersect_key($metadata, array_flip($fields));
+ $metadata = array_intersect_key($metadata, array_flip($fields));
+ $metadata['activity_text'] = [
+ 'title' => ts('Activity Text'),
+ 'type' => CRM_Utils_Type::T_STRING,
+ 'is_pseudofield' => TRUE,
+ ];
+ return $metadata;
}
/**
}
$this->_done = TRUE;
-
+ $this->setFormValues();
if (!empty($_POST)) {
- $this->_formValues = $this->controller->exportValues($this->_name);
$specialParams = [
'activity_type_id',
'status_id',
'priority_id',
- 'activity_text',
];
$changeNames = [
'status_id' => 'activity_status_id',
return;
}
- $input = $value = trim($value);
+ $input = $value = is_array($value) ? trim($value['LIKE']) : trim($value);
if (!strlen($value)) {
return;
public function postProcess() {
$this->set('isAdvanced', '1');
+ $this->setFormValues();
// get user submitted values
// get it from controller only if form has been submitted, else preProcess has set this
if (!empty($_POST)) {
- $this->_formValues = $this->controller->exportValues($this->_name);
$this->normalizeFormValues();
// FIXME: couldn't figure out a good place to do this,
// FIXME: so leaving this as a dependency for now
'activity_type_id',
'status_id',
'priority_id',
- 'activity_subject',
- 'activity_details',
'contribution_page_id',
'contribution_product_id',
'payment_instrument_id',
$this->_done = TRUE;
- if (!empty($_POST) && !$this->_force) {
- $this->_formValues = $this->controller->exportValues($this->_name);
- }
- $this->convertTextStringsToUseLikeOperator();
+ $this->setFormValues();
$this->fixFormValues();
// We don't show test records in summaries or dashboards
return $defaults;
}
+ /**
+ * Set the form values based on input and preliminary processing.
+ */
+ protected function setFormValues() {
+ if (!empty($_POST) && !$this->_force) {
+ $this->_formValues = $this->controller->exportValues($this->_name);
+ }
+ $this->convertTextStringsToUseLikeOperator();
+ }
+
/**
* Common buildForm tasks required by all searches.
*/
elseif (isset($fields[$fieldName]['title'])) {
$props['label'] = $fields[$fieldName]['title'];
}
- $this->addField($fieldName, $props);
+ if (empty($fieldSpec['is_pseudofield'])) {
+ $this->addField($fieldName, $props);
+ }
}
}
}
* Note this will only pick up fields declared via metadata.
*/
protected function convertTextStringsToUseLikeOperator() {
- foreach (CRM_Utils_Array::value($this->getDefaultEntity(), $this->getSearchFieldMetadata(), []) as $fieldName => $field) {
- if (!empty($this->_formValues[$fieldName]) && empty($field['options']) && empty($field['pseudoconstant'])) {
- if (in_array($field['type'], [CRM_Utils_Type::T_STRING, CRM_Utils_Type::T_TEXT])) {
- $this->_formValues[$fieldName] = ['LIKE' => CRM_Contact_BAO_Query::getWildCardedValue(TRUE, 'LIKE', $this->_formValues[$fieldName])];
+ foreach ($this->getSearchFieldMetadata() as $entity => $fields) {
+ foreach ($fields as $fieldName => $field) {
+ if (!empty($this->_formValues[$fieldName]) && empty($field['options']) && empty($field['pseudoconstant'])) {
+ if (in_array($field['type'], [CRM_Utils_Type::T_STRING, CRM_Utils_Type::T_TEXT])) {
+ $this->_formValues[$fieldName] = ['LIKE' => CRM_Contact_BAO_Query::getWildCardedValue(TRUE, 'LIKE', $this->_formValues[$fieldName])];
+ }
}
}
}