Skip to content

Commit

Permalink
fix error in getImageList, when value is not valid json
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno17 committed Feb 21, 2024
1 parent 9ba7808 commit 352a909
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions core/components/migx/elements/snippets/getimagelist.snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
$randomize = $modx->getOption('randomize', $scriptProperties, false);
$preselectLimit = $modx->getOption('preselectLimit', $scriptProperties, 0); // when random preselect important images
$where = $modx->getOption('where', $scriptProperties, '');
$where = !empty($where) ? $modx->fromJSON($where) : array();
$where = !empty($where) ? json_decode($where,true) : array();
$sort = $modx->getOption('sort', $scriptProperties, '');
$sort = !empty($sort) ? $modx->fromJSON($sort) : array();
$sort = !empty($sort) ? json_decode($sort,true) : array();
$toSeparatePlaceholders = $modx->getOption('toSeparatePlaceholders', $scriptProperties, false);
$toPlaceholder = $modx->getOption('toPlaceholder', $scriptProperties, false);
$outputSeparator = $modx->getOption('outputSeparator', $scriptProperties, '');
Expand All @@ -73,7 +73,7 @@
$addfields = $modx->getOption('addfields', $scriptProperties, '');
$addfields = !empty($addfields) ? explode(',', $addfields) : null;
//split json into parts
$splits = $modx->fromJson($modx->getOption('splits', $scriptProperties, 0));
$splits = json_decode($modx->getOption('splits', $scriptProperties, 0),true);
$splitTpl = $modx->getOption('splitTpl', $scriptProperties, '');
$splitSeparator = $modx->getOption('splitSeparator', $scriptProperties, '');
$inheritFrom = $modx->getOption('inheritFrom', $scriptProperties, ''); //commaseparated list of resource-ids or/and the keyword 'parents' where to inherit from
Expand Down Expand Up @@ -108,7 +108,7 @@
}
if (empty($formtabs) && isset($properties['formtabs'])) {
//try to get formtabs and its fields from properties
$formtabs = $modx->fromJSON($properties['formtabs']);
$formtabs = json_decode($properties['formtabs'],true);
}

if (!empty($properties['basePath'])) {
Expand Down Expand Up @@ -174,7 +174,11 @@

//echo $outputvalue.'<br/><br/>';

$items = $modx->fromJSON($outputvalue);
$items = json_decode($outputvalue,true);

if (!is_array($items)){
$items = [];
}

// where filter
if (is_array($where) && count($where) > 0) {
Expand Down Expand Up @@ -249,7 +253,7 @@
if (is_array($value)) {
if (is_array($value[0])) {
//nested array - convert to json
$value = $modx->toJson($value);
$value = json_encode($value);
} else {
$value = implode('||', $value); //handle arrays (checkboxes, multiselects)
}
Expand Down Expand Up @@ -411,7 +415,7 @@


if ($toJsonPlaceholder) {
$modx->setPlaceholder($toJsonPlaceholder, $modx->toJson($output));
$modx->setPlaceholder($toJsonPlaceholder, json_encode($output));
return '';
}

Expand Down

0 comments on commit 352a909

Please sign in to comment.