diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d303ca057e4634b729a93f0a9b2161e28d6c9b1..8475296b66daf60de56108db357afb731f8b035d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Version 1.113 (not yet released) +* Fixed issue with search output where all records are selected by default + # Version 1.112 * Fixed issue with API permissions. diff --git a/CRM/DataprocessorSearch/Form/AbstractSearch.php b/CRM/DataprocessorSearch/Form/AbstractSearch.php index f653e60cd6cc94de452f0e5f602d41645b866366..37cf4626b826665a55666ba667f9e85de9443699 100644 --- a/CRM/DataprocessorSearch/Form/AbstractSearch.php +++ b/CRM/DataprocessorSearch/Form/AbstractSearch.php @@ -506,8 +506,8 @@ abstract class CRM_DataprocessorSearch_Form_AbstractSearch extends CRM_Dataproce parent::buildQuickForm(); $this->buildCriteriaForm(); - $selectedIds = $this->getSelectedIds(true); - $this->assign_by_ref('selectedIds', $selectedIds); + $selectedIds = $this->getSelectedIds(true, true); + $this->assign('selectedIds', $selectedIds); $this->add('hidden', 'context'); $this->add('hidden', CRM_Utils_Sort::SORT_ID); @@ -596,25 +596,28 @@ abstract class CRM_DataprocessorSearch_Form_AbstractSearch extends CRM_Dataproce /** * Returns the selected IDs. * + * @param bool $skipSelectAll + * @param bool $loadFresh + * * @return array */ - public function getSelectedIds(bool $skipSelectAll=false): array { - if (!empty($this->entityIDs) && is_array($this->entityIDs)) { + public function getSelectedIds(bool $skipSelectAll=false, bool $loadFresh = false): array { + if (!$loadFresh && !empty($this->entityIDs) && is_array($this->entityIDs)) { return $this->entityIDs; } - $this->entityIDs = []; + $entityIDs = []; // We use ajax to handle selections only if the search results component_mode is set to "contacts" if ($this->usePrevNextCache()) { $this->addClass('crm-ajax-selection-form'); $selectedIdsArr = CRM_DataprocessorSearch_Utils_PrevNextCache::getSelection($this->getCacheKey()); if (isset($selectedIdsArr[$this->getCacheKey()]) && is_array($selectedIdsArr[$this->getCacheKey()])) { - $this->entityIDs = array_keys($selectedIdsArr[$this->getCacheKey()]); + $entityIDs = array_keys($selectedIdsArr[$this->getCacheKey()]); } } else { if (isset($this->_formValues['radio_ts']) && $this->_formValues['radio_ts'] == 'ts_sel') { foreach ($this->_formValues as $name => $value) { if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { - $this->entityIDs[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); + $entityIDs[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); } } } elseif (!$skipSelectAll && (!isset($this->_formValues['radio_ts']) || $this->_formValues['radio_ts'] == 'ts_all')) { @@ -629,7 +632,7 @@ abstract class CRM_DataprocessorSearch_Form_AbstractSearch extends CRM_Dataproce while ($record = $this->dataProcessorClass->getDataFlow() ->nextRecord()) { if (!empty($id_field) && isset($record[$id_field])) { - $this->entityIDs[] = $record[$id_field]->rawValue; + $entityIDs[] = $record[$id_field]->rawValue; } } } catch (EndOfFlowException|DataFlowException|InvalidFlowException $e) { @@ -637,7 +640,10 @@ abstract class CRM_DataprocessorSearch_Form_AbstractSearch extends CRM_Dataproce } } } - return $this->entityIDs; + if ($loadFresh && !$skipSelectAll) { + $this->entityIDs = $entityIDs; + } + return $entityIDs; } /**