SearchKit - Correctly process filters passed through Afform from javascript
authorColeman Watts <coleman@civicrm.org>
Wed, 15 Sep 2021 17:17:04 +0000 (13:17 -0400)
committerColeman Watts <coleman@civicrm.org>
Wed, 15 Sep 2021 17:17:04 +0000 (13:17 -0400)
ext/search_kit/Civi/Api4/Action/SearchDisplay/AbstractRunAction.php

index f1578097d21ce47a4096c8fc22efbe12911d1fa1..66b0d2b7b9365abd63da676e7073c7001762e3bd 100644 (file)
@@ -429,10 +429,16 @@ abstract class AbstractRunAction extends \Civi\Api4\Generic\AbstractAction {
     if ($filterAttr && is_string($filterAttr) && $filterAttr[0] === '{') {
       foreach (\CRM_Utils_JS::decode($filterAttr) as $filterKey => $filterVal) {
         // Automatically apply filters from the markup if they have a value
-        // (if it's a javascript variable it will have come back from decode() as NULL and we'll ignore it).
-        unset($this->filters[$filterKey]);
-        if ($this->hasValue($filterVal)) {
-          $this->applyFilter(explode(',', $filterKey), $filterVal);
+        if ($filterVal !== NULL) {
+          unset($this->filters[$filterKey]);
+          if ($this->hasValue($filterVal)) {
+            $this->applyFilter(explode(',', $filterKey), $filterVal);
+          }
+        }
+        // If it's a javascript variable it will have come back from decode() as NULL;
+        // whitelist it to allow it to be passed to this api from javascript.
+        else {
+          $filterKeys[] = $filterKey;
         }
       }
     }