‪TYPO3CMS  ‪main
DatabaseQueryProcessor.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 
48 {
49  public function ‪__construct(protected readonly ‪ContentDataProcessor $contentDataProcessor) {}
50 
61  public function ‪process(‪ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
62  {
63  if (isset($processorConfiguration['if.']) && !$cObj->‪checkIf($processorConfiguration['if.'])) {
64  return $processedData;
65  }
66 
67  // the table to query, if none given, exit
68  $tableName = $cObj->‪stdWrapValue('table', $processorConfiguration);
69  if (empty($tableName)) {
70  return $processedData;
71  }
72  if (isset($processorConfiguration['table.'])) {
73  unset($processorConfiguration['table.']);
74  }
75  if (isset($processorConfiguration['table'])) {
76  unset($processorConfiguration['table']);
77  }
78 
79  // The variable to be used within the result
80  $targetVariableName = $cObj->‪stdWrapValue('as', $processorConfiguration, 'records');
81 
82  // Execute a SQL statement to fetch the records
83  $records = $cObj->‪getRecords($tableName, $processorConfiguration);
84  $request = $cObj->‪getRequest();
85  $processedRecordVariables = [];
86  foreach ($records as $key => ‪$record) {
87  $recordContentObjectRenderer = GeneralUtility::makeInstance(ContentObjectRenderer::class);
88  $recordContentObjectRenderer->setRequest($request);
89  $recordContentObjectRenderer->start(‪$record, $tableName);
90  $processedRecordVariables[$key] = ['data' => ‪$record];
91  $processedRecordVariables[$key] = $this->contentDataProcessor->process($recordContentObjectRenderer, $processorConfiguration, $processedRecordVariables[$key]);
92  }
93 
94  $processedData[$targetVariableName] = $processedRecordVariables;
95 
96  return $processedData;
97  }
98 }
‪TYPO3\CMS\Frontend\ContentObject\ContentDataProcessor
Definition: ContentDataProcessor.php:27
‪TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor
Definition: DatabaseQueryProcessor.php:48
‪TYPO3\CMS\Frontend\DataProcessing
Definition: CommaSeparatedValueProcessor.php:16
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\checkIf
‪checkIf($conf)
Definition: ContentObjectRenderer.php:2442
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\stdWrapValue
‪string int bool null stdWrapValue($key, array $config, $defaultValue='')
Definition: ContentObjectRenderer.php:1138
‪TYPO3\CMS\Webhooks\Message\$record
‪identifier readonly int readonly array $record
Definition: PageModificationMessage.php:36
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getRecords
‪array getRecords($tableName, array $queryConfiguration)
Definition: ContentObjectRenderer.php:4688
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer\getRequest
‪getRequest()
Definition: ContentObjectRenderer.php:5521
‪TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor\__construct
‪__construct(protected readonly ContentDataProcessor $contentDataProcessor)
Definition: DatabaseQueryProcessor.php:49
‪TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface
Definition: DataProcessorInterface.php:23
‪TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
Definition: ContentObjectRenderer.php:102
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Frontend\DataProcessing\DatabaseQueryProcessor\process
‪array process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData)
Definition: DatabaseQueryProcessor.php:61