diff --git a/Classes/ContentObject/JsonContentContentObject.php b/Classes/ContentObject/JsonContentContentObject.php index 0ad77827..1a91ead6 100755 --- a/Classes/ContentObject/JsonContentContentObject.php +++ b/Classes/ContentObject/JsonContentContentObject.php @@ -28,14 +28,17 @@ use const JSON_FORCE_OBJECT; /** - * CONTENT_JSON Content object behaves & has the same options as standard TYPO3' Content - * main difference is content is grouped by colPol field & encoded into JSON by default. + * This cObject basically behaves like TYPO3's CONTENT, + * the main difference is that content elements are + * grouped by colPol & encoded into JSON by default. * - * CONTENT_JSON has the same options as CONTENT, also adds two new options for edge cases in json context + * CONTENT_JSON has the same options as CONTENT but also + * offers two new options for edge cases in json context. * * ** merge ** option - * New option allows to generate another CONTENT_JSON call in one definition & then merge both results into one dataset - * (useful for handling slide feature of CONTENT cObject) + * This option allows to generate another CONTENT_JSON call + * in one definition & then merge both results into one + * dataset (useful for handling slide feature of CONTENT cObject). * * for example: * @@ -57,7 +60,8 @@ * } * * ** doNotGroupByColPos = 0(default)|1 ** - * Option allows return of flat array (without grouping by colPos) encoded into JSON + * This option allows to return a flat array (without grouping + * by colPos) but still encoded into JSON. * * lib.content = CONTENT_JSON * lib.content { @@ -67,6 +71,7 @@ * where = {#colPos} != 1 * } * doNotGroupByColPos = 1 + * } */ class JsonContentContentObject extends ContentContentObject { diff --git a/Classes/ContentObject/JsonContentObject.php b/Classes/ContentObject/JsonContentObject.php index a63e9674..4d1bfd78 100755 --- a/Classes/ContentObject/JsonContentObject.php +++ b/Classes/ContentObject/JsonContentObject.php @@ -54,6 +54,10 @@ public function __construct(ContentDataProcessor $contentDataProcessor = null) */ public function render($conf = []): string { + if (!empty($conf['if.']) && !$this->cObj->checkIf($conf['if.'])) { + return ''; + } + $data = []; if (!is_array($conf)) { diff --git a/Documentation/Developer/Index.rst b/Documentation/Developer/Index.rst index edd82956..6241e096 100644 --- a/Documentation/Developer/Index.rst +++ b/Documentation/Developer/Index.rst @@ -10,6 +10,111 @@ This chapter will explain different usecases for developer working with `headles .. _developer-plugin-extbase: +New cObjects +============ + +EXT:headless comes with a bunch of new cObjects to be used via TypoScript: + +* BOOL +* FLOAT +* INT +* JSON +* JSON_CONTENT + +`BOOL`, `FLOAT` and `INT` are basically like `TEXT` (with `value` and `stdWrap` properties!) but make sure their result is being cast to bool, float or int. + +JSON +---- + +To build and render a JSON object into your page output. + +.. code-block:: typoscript + + lib.meta = JSON + lib.meta { + if.isTrue = 1 + fields { + title = TEXT + title { + field = seo_title + stdWrap.ifEmpty.cObject = TEXT + stdWrap.ifEmpty.cObject { + field = title + } + } + robots { + fields { + noIndex = BOOL + noIndex.field = no_index + } + } + ogImage = TEXT + ogImage { + dataProcessing { + 10 = FriendsOfTYPO3\Headless\DataProcessing\FilesProcessor + 10 { + as = media + references.fieldName = og_image + processingConfiguration { + returnFlattenObject = 1 + } + } + } + } + } + dataProcessing { + } + stdWrap { + } + } + +JSON_CONTENT +------------ + +This cObject basically behaves like TYPO3's `CONTENT`, the main difference is that content elements are grouped by `colPol` & encoded into JSON by default. + +`CONTENT_JSON` has the same options as `CONTENT` but also offers two new options for edge cases in json context. + +**merge** + +This option allows to generate another `CONTENT_JSON` call in one definition & then merge both results into one dataset +(useful for handling slide feature of CONTENT cObject). + +.. code-block:: typoscript + + lib.content = CONTENT_JSON + lib.content { + table = tt_content + select { + orderBy = sorting + where = {#colPos} != 1 + } + merge { + table = tt_content + select { + orderBy = sorting + where = {#colPos} = 1 + } + slide = -1 + } + } + +**doNotGroupByColPos = 0(default)|1** + +This option allows to return a flat array (without grouping by colPos) but still encoded into JSON. + +.. code-block:: typoscript + + lib.content = CONTENT_JSON + lib.content { + table = tt_content + select { + orderBy = sorting + where = {#colPos} != 1 + } + doNotGroupByColPos = 1 + } + Internal Extbase plugins ======================== @@ -274,7 +379,7 @@ Here's an example of how to override the meta object by data from a DB record: lib.meta.stdWrap.override.cObject = JSON lib.meta.stdWrap.override.cObject { - stdWrap.if.isTrue.data = GP:tx_news_pi1|news + if.isTrue.data = GP:tx_news_pi1|news dataProcessing.10 = FriendsOfTYPO3\Headless\DataProcessing\DatabaseQueryProcessor dataProcessing.10 { table = tx_news_domain_model_news diff --git a/Tests/Unit/ContentObject/JsonContentObjectTest.php b/Tests/Unit/ContentObject/JsonContentObjectTest.php index 6975b60f..d570b929 100644 --- a/Tests/Unit/ContentObject/JsonContentObjectTest.php +++ b/Tests/Unit/ContentObject/JsonContentObjectTest.php @@ -145,6 +145,8 @@ public function dataProvider(): array return [ [[], '[]'], [null, '[]'], + [['if.' => ['isTrue' => 0], 'fields.' => ['test' => 'TEXT', 'test.' => ['value' => '1']]], ''], + [['if.' => ['isTrue' => 1], 'fields.' => ['test' => 'TEXT', 'test.' => ['value' => '1']]], json_encode(['test' => '1'])], [['stdWrap.' => ['wrap' => '{"wrapped":|}']], json_encode(['wrapped' => []])], [['dataProcessing.' => ['10' => 'FriendsOfTYPO3\Headless\Tests\Unit\ContentObject\DataProcessingExample', '10.' => ['as' => 'sites']]], json_encode(['SomeCustomProcessing'])], [['fields.' => ['test' => 'TEXT', 'test.' => ['value' => '1']]], json_encode(['test' => '1'])],