Skip to content

Commit

Permalink
[FEATURE] Allow cast value to bool via boolval = 1 (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
twoldanski authored Apr 28, 2023
1 parent 00a4b46 commit dd87097
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Classes/ContentObject/JsonContentObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public function cObjGet(array $setup, string $addKey = ''): array
if ((isset($conf['floatval']) && $conf['floatval']) || $theValue === 'FLOAT') {
$content[$theKey] = (float)$content[$theKey];
}
if ($theValue === 'BOOL') {
$content[$theKey] = (bool)$content[$theKey];
if ((isset($conf['boolval']) && $conf['boolval']) || $theValue === 'BOOL') {
$content[$theKey] = (bool)(int)$content[$theKey];
}
if ($theValue === 'USER_INT' || strpos((string)$content[$theKey], '<!--INT_SCRIPT.') === 0) {
$content[$theKey] = $this->headlessUserInt->wrap($content[$theKey]);
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/ContentObject/JsonContentObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public function dataProvider(): array
[['dataProcessing.' => ['10' => 'FriendsOfTYPO3\Headless\Tests\Unit\ContentObject\DataProcessingExample', '10.' => ['as' => 'sites']]], json_encode(['SomeCustomProcessing'])],
[['fields.' => ['test' => 'TEXT', 'test.' => ['value' => '1']]], json_encode(['test' => '1'])],
[['fields.' => ['test' => 'TEXT', 'test.' => ['value' => '']]], json_encode(['test' => ''])],
[['fields.' => ['test' => 'TEXT', 'test.' => ['value' => '1', 'boolval' => 1]]], json_encode(['test' => true])],
[['fields.' => ['test' => 'TEXT', 'test.' => ['value' => '0', 'boolval' => 1]]], json_encode(['test' => false])],
[['fields.' => ['test' => 'TEXT', 'test.' => ['value' => 'false', 'boolval' => 1]]], json_encode(['test' => false])],
[['fields.' => ['test' => 'TEXT', 'test.' => ['value' => '', 'ifEmptyReturnNull' => 0]]], json_encode(['test' => ''])],
[['fields.' => ['test' => 'TEXT', 'test.' => ['value' => '', 'ifEmptyReturnNull' => 1]]], json_encode(['test' => null])],
[['fields.' => ['test' => 'TEXT', 'test.' => ['value' => null, 'stdWrap.' => ['ifEmpty' => '{}']]]], json_encode(['test' => new \stdClass()])],
Expand Down

0 comments on commit dd87097

Please sign in to comment.