From c7ba08ecb969585d251f64d80f3f2996dd779e5d Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 7 Feb 2025 14:21:58 -0500 Subject: [PATCH] Update ProcessController::jsonMessage() method so that it supports array argument, primarily for internal debugging purposes --- wire/core/ProcessController.php | 20 +++++++++++-------- .../ProcessPageSearch.module | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/wire/core/ProcessController.php b/wire/core/ProcessController.php index 76bb42c6..d6512ade 100644 --- a/wire/core/ProcessController.php +++ b/wire/core/ProcessController.php @@ -486,18 +486,22 @@ class ProcessController extends Wire { /** * Generate a message in JSON format, for use with AJAX output * - * @param string $msg - * @param bool $error - * @param bool $allowMarkup + * @param string|array $msg Message string or in 3.0.246+ also accepts an array of extra data + * When using an array, please include a 'message' index with text about the error or non-error. + * @param bool $error Is this in error message? Default is true, or specify false if not. + * @param bool $allowMarkup Allow markup in message? Applies only to $msg string or 'message' index of array (default=false) * @return string JSON encoded string * */ public function jsonMessage($msg, $error = false, $allowMarkup = false) { - if(!$allowMarkup) $msg = $this->wire()->sanitizer->entities($msg); - return json_encode(array( - 'error' => (bool) $error, - 'message' => (string) $msg - )); + $a = array('error' => (bool) $error, 'message' => ''); + if(is_array($msg)) { + $a = array_merge($a, $msg); + } else { + $a['message'] = (string) $msg; + } + if(!$allowMarkup) $a['message'] = $this->wire()->sanitizer->entities($a['message']); + return json_encode($a); } /** diff --git a/wire/modules/Process/ProcessPageSearch/ProcessPageSearch.module b/wire/modules/Process/ProcessPageSearch/ProcessPageSearch.module index 1a3d1a5c..85d3e813 100644 --- a/wire/modules/Process/ProcessPageSearch/ProcessPageSearch.module +++ b/wire/modules/Process/ProcessPageSearch/ProcessPageSearch.module @@ -440,7 +440,7 @@ class ProcessPageSearch extends Process implements ConfigurableModule { } // foreach input - if(strpos($selectors['for'], 'limit=') && $limit === $this->resultLimit) { + if(isset($selectors['for']) && strpos($selectors['for'], 'limit=') && $limit === $this->resultLimit) { if(preg_match('/\blimit=(\d+),?/', $selectors['for'], $matches)) { $limit = (int) $matches[1]; $selectors['for'] = str_replace($matches[0], '', $selectors['for']);