Fix support for relative dates in urls
authoreileen <emcnaughton@wikimedia.org>
Sat, 27 Jul 2019 05:21:27 +0000 (17:21 +1200)
committereileen <emcnaughton@wikimedia.org>
Sat, 27 Jul 2019 05:21:27 +0000 (17:21 +1200)
This improves support for relative dates for fields that have been converted.

For example

http://dmaster.local/civicrm/contribute/search?reset=1&receive_date_relative=this.year&force=1

Now works to render donations 'This Calendar Year'

CRM/Core/Form/Search.php

index 26f7de8e4af93a5b30fdde9ca0bb55b452426741..80ef7ca4f5f6d841653b28b0ff3edaa7a884a855 100644 (file)
@@ -268,6 +268,8 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
    * @param string $entity
    *
    * @return array
+   *
+   * @throws \CRM_Core_Exception
    */
   protected function getEntityDefaults($entity) {
     $defaults = [];
@@ -285,6 +287,12 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
             $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;
           }
+          else {
+            $relative = CRM_Utils_Request::retrieveValue($fieldName . '_relative', 'String', NULL, NULL, 'GET');
+            if (!empty($relative) && isset(CRM_Core_OptionGroup::values('relative_date_filters')[$relative])) {
+              $defaults[$fieldName . '_relative'] = $relative;
+            }
+          }
         }
       }
     }