Commit 9cf368cf by Van

add conditions back

parent 1173d518
......@@ -32,26 +32,28 @@ class CustomQueriesExtension extends SimpleExtension
$subject = $event->getSubject();
/** @var \Bolt\Storage\Mapping\ContentType $contentType */
$contentType = $subject->getContentType();
$fields = $contentType->getFields();
$customQueryFields = [];
foreach ($fields as $key => $field) {
if($field['class'] === 'customQuery') {
$customQueryFields[$key] = true;
break;
if ($contentType){
$fields = $contentType->getFields();
$customQueryFields = [];
foreach ($fields as $key => $field) {
if($field['class'] === 'customQuery') {
$customQueryFields[$key] = true;
break;
}
}
}
if(!empty($customQueryFields)) {
foreach ($customQueryFields as $field => $customQueryField) {
$fieldJson = $subject->get($field);
if($fieldJson) {
$jsonArray = \json_decode($fieldJson, true);
$jsonArray['count'] = $this->countGroupedByContent($jsonArray, $fieldJson);
if(!empty($customQueryFields)) {
foreach ($customQueryFields as $field => $customQueryField) {
$fieldJson = $subject->get($field);
if($fieldJson) {
$jsonArray = \json_decode($fieldJson, true);
$jsonArray['count'] = $this->countGroupedByContent($jsonArray, $fieldJson);
$newFieldJson = \json_encode($jsonArray);
$newFieldJson = \json_encode($jsonArray);
$subject->set($field, $newFieldJson);
$subject->set($field, $newFieldJson);
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment