1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-08 07:47:00 +02:00

Update ProcessController::jsonMessage() method so that it supports array argument, primarily for internal debugging purposes

This commit is contained in:
Ryan Cramer
2025-02-07 14:21:58 -05:00
parent 59ae7f4c7f
commit c7ba08ecb9
2 changed files with 13 additions and 9 deletions

View File

@@ -486,18 +486,22 @@ class ProcessController extends Wire {
/** /**
* Generate a message in JSON format, for use with AJAX output * Generate a message in JSON format, for use with AJAX output
* *
* @param string $msg * @param string|array $msg Message string or in 3.0.246+ also accepts an array of extra data
* @param bool $error * When using an array, please include a 'message' index with text about the error or non-error.
* @param bool $allowMarkup * @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 * @return string JSON encoded string
* *
*/ */
public function jsonMessage($msg, $error = false, $allowMarkup = false) { public function jsonMessage($msg, $error = false, $allowMarkup = false) {
if(!$allowMarkup) $msg = $this->wire()->sanitizer->entities($msg); $a = array('error' => (bool) $error, 'message' => '');
return json_encode(array( if(is_array($msg)) {
'error' => (bool) $error, $a = array_merge($a, $msg);
'message' => (string) $msg } else {
)); $a['message'] = (string) $msg;
}
if(!$allowMarkup) $a['message'] = $this->wire()->sanitizer->entities($a['message']);
return json_encode($a);
} }
/** /**

View File

@@ -440,7 +440,7 @@ class ProcessPageSearch extends Process implements ConfigurableModule {
} // foreach input } // 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)) { if(preg_match('/\blimit=(\d+),?/', $selectors['for'], $matches)) {
$limit = (int) $matches[1]; $limit = (int) $matches[1];
$selectors['for'] = str_replace($matches[0], '', $selectors['for']); $selectors['for'] = str_replace($matches[0], '', $selectors['for']);