From c5c1703423a83c627c9a4ae17b67ddc57031c949 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 21 Jun 2019 10:20:06 -0400 Subject: [PATCH] Fix url support for receive_date_high & receive_date_low This ensures that the following url params are supported receive_date_high=20180101 receive_date_low.... contribution_cancel_date_high contribution_cancel_date_low invoice_number= Note that in doing this I fixed the new & somewhat experimental default function to use field uniquenames rather than field names (as this is how they are added to the form & it was required for cancel_date. Support for receive_date_relative=this.day etc would be trivial but not yet tackled Also I see that we historically support 'start' and 'end' I think we can tackle this by doing something like if start is set then ->set('contribution_date_low' - probably with a deprecation notice) I will leave for a follow up though --- CRM/Contribute/Form/Search.php | 2 ++ CRM/Core/Form/Search.php | 18 +++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CRM/Contribute/Form/Search.php b/CRM/Contribute/Form/Search.php index 847f64688b..92092f4422 100644 --- a/CRM/Contribute/Form/Search.php +++ b/CRM/Contribute/Form/Search.php @@ -149,8 +149,10 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { * Set defaults. * * @return array + * @throws \Exception */ public function setDefaultValues() { + $this->_defaults = parent::setDefaultValues(); if (empty($this->_defaults['contribution_status'])) { $this->_defaults['contribution_status'][1] = 1; } diff --git a/CRM/Core/Form/Search.php b/CRM/Core/Form/Search.php index 865cb9e694..481051512f 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -251,19 +251,19 @@ class CRM_Core_Form_Search extends CRM_Core_Form { */ protected function getEntityDefaults($entity) { $defaults = []; - foreach ($this->getSearchFieldMetadata()[$entity] as $fieldSpec) { + foreach ($this->getSearchFieldMetadata()[$entity] as $fieldName => $fieldSpec) { if (empty($_POST[$fieldSpec['name']])) { - $value = CRM_Utils_Request::retrieveValue($fieldSpec['name'], $this->getValidationTypeForField($entity, $fieldSpec['name']), FALSE, NULL, 'GET'); - if ($value !== FALSE) { - $defaults[$fieldSpec['name']] = $value; + $value = CRM_Utils_Request::retrieveValue($fieldName, $this->getValidationTypeForField($entity, $fieldName), FALSE, NULL, 'GET'); + if ($value !== NULL) { + $defaults[$fieldName] = $value; } if ($fieldSpec['type'] === CRM_Utils_Type::T_DATE || ($fieldSpec['type'] === CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME)) { - $low = CRM_Utils_Request::retrieveValue($fieldSpec['name'] . '_low', 'Timestamp', FALSE, NULL, 'GET'); - $high = CRM_Utils_Request::retrieveValue($fieldSpec['name'] . '_high', 'Timestamp', FALSE, NULL, 'GET'); + $low = CRM_Utils_Request::retrieveValue($fieldName . '_low', 'Timestamp', FALSE, NULL, 'GET'); + $high = CRM_Utils_Request::retrieveValue($fieldName . '_high', 'Timestamp', FALSE, NULL, 'GET'); if ($low !== FALSE || $high !== FALSE) { - $defaults[$fieldSpec['name'] . '_relative'] = 0; - $defaults[$fieldSpec['name'] . '_low'] = $low ? date('Y-m-d H:i:s', strtotime($low)) : NULL; - $defaults[$fieldSpec['name'] . '_high'] = $high ? date('Y-m-d H:i:s', strtotime($high)) : NULL; + $defaults[$fieldName . '_relative'] = 0; + $defaults[$fieldName . '_low'] = $low ? date('Y-m-d H:i:s', strtotime($low)) : NULL; + $defaults[$fieldName . '_high'] = $high ? date('Y-m-d H:i:s', strtotime($high)) : NULL; } } } -- 2.25.1