Skip to content

Commit

Permalink
[FEATURE] Add option "ifEmptyUnsetKey" to JSON cObject (#650)
Browse files Browse the repository at this point in the history
This TypoScript option works similar to "ifEmptyReturnNull",
however, the option uses the unset() feature to actually remove
the key from the json output instead of setting this to null.

The code checks for "" and an explicit "false" (bool) when using
the cObject = BOOL

Fixes: #649
  • Loading branch information
bmack authored Oct 2, 2023
1 parent 7d5a90e commit bd021af
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Classes/ContentObject/JsonContentObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ public function cObjGet(array $setup, string $addKey = ''): array
if ((int)($conf['ifEmptyReturnNull'] ?? 0) === 1 && $content[$theKey] === '') {
$content[$theKey] = null;
}
if ((int)($conf['ifEmptyUnsetKey'] ?? 0) === 1 && ($content[$theKey] === '' || $content[$theKey] === false)) {
unset($content[$theKey]);
}
if (!empty($contentDataProcessing['dataProcessing.'])) {
$content[rtrim($theKey, '.')] = $this->processFieldWithDataProcessing($contentDataProcessing);
}
Expand Down

0 comments on commit bd021af

Please sign in to comment.