Skip to content

Commit

Permalink
Fix activity search to work by url params
Browse files Browse the repository at this point in the history
It seems to be missing the call to the parent fn

Note I feel like the parent should also handle some of the rows below in future
  • Loading branch information
eileenmcnaughton committed Nov 29, 2019
1 parent 124f041 commit 606855e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
3 changes: 3 additions & 0 deletions CRM/Activity/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ public static function getSearchFieldMetadata() {
'title' => ts('Activity Text'),
'type' => CRM_Utils_Type::T_STRING,
'is_pseudofield' => TRUE,
'html' => [
'type' => 'Text',
],
];
return $metadata;
}
Expand Down
52 changes: 23 additions & 29 deletions CRM/Activity/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ class CRM_Activity_Form_Search extends CRM_Core_Form_Search {
*
* @var bool
*/
protected $_limit = NULL;
protected $_limit;

/**
* Prefix for the controller.
* @var string
*/
protected $_prefix = "activity_";
protected $_prefix = 'activity_';

/**
* The saved search ID retrieved from the GET vars.
Expand All @@ -63,6 +63,9 @@ public function getDefaultEntity() {

/**
* Processing needed for buildForm and later.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function preProcess() {
$this->set('searchFormName', 'Search');
Expand All @@ -73,37 +76,14 @@ public function preProcess() {

$this->_done = FALSE;

$this->loadStandardSearchOptionsFromUrl();

// get user submitted values
// get it from controller only if form has been submitted, else preProcess has set this
if (!empty($_POST) && !$this->controller->isModal()) {
$this->_formValues = $this->controller->exportValues($this->_name);
}
else {
$this->_formValues = $this->get('formValues');

if ($this->_force) {
// If we force the search then merge form values with url values
// and set submit values to form values.
// @todo this is not good security practice. Instead define the fields in metadata & use
// getEntityDefaults.
$this->_formValues = array_merge((array) $this->_formValues, CRM_Utils_Request::exportValues());
$this->_submitValues = $this->_formValues;
}
}
parent::preProcess();

if (empty($this->_formValues)) {
if (isset($this->_ssID)) {
$this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
}
}

if ($this->_force) {
$this->postProcess();
$this->set('force', 0);
}

$sortID = NULL;
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
Expand Down Expand Up @@ -143,6 +123,9 @@ public function preProcess() {

/**
* Build the form object.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function buildQuickForm() {
parent::buildQuickForm();
Expand Down Expand Up @@ -210,7 +193,6 @@ public function postProcess() {

$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);

$this->set('formValues', $this->_formValues);
$this->set('queryParams', $this->_queryParams);

$buttonName = $this->controller->getButtonName();
Expand Down Expand Up @@ -242,7 +224,7 @@ public function postProcess() {
$selector->setKey($this->controller->_key);

$prefix = NULL;
if ($this->_context == 'basic' || $this->_context == 'user') {
if ($this->_context === 'basic' || $this->_context === 'user') {
$prefix = $this->_prefix;
}

Expand All @@ -257,12 +239,17 @@ public function postProcess() {
$controller->setEmbedded(TRUE);
$query = &$selector->getQuery();

if ($this->_context == 'user') {
if ($this->_context === 'user') {
$query->setSkipPermission(TRUE);
}
$controller->run();
}

/**
* Probably more hackery than anything else.
*
* @throws \CRM_Core_Exception
*/
public function fixFormValues() {
if (!$this->_force) {
return;
Expand Down Expand Up @@ -337,6 +324,13 @@ public function getTitle() {
return ts('Find Activities');
}

/**
* Get metadata for the entity fields.
*
* @return array
*
* @throws \CiviCRM_API3_Exception
*/
protected function getEntityMetadata() {
return CRM_Activity_BAO_Query::getSearchFieldMetadata();
}
Expand Down

0 comments on commit 606855e

Please sign in to comment.