ew_bloggy/Classes/DataProcessing/BlogPostProcessor.php
2025-01-21 20:22:57 +01:00

62 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
/*
* This file is developed by evoWeb.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
namespace Evoweb\EwBloggy\DataProcessing;
use Evoweb\EwBloggy\Domain\Repository\PostRepository;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
/**
* Fetch blog records from the database, using the default .select syntax from TypoScript.
*
* This way, e.g. a FLUIDTEMPLATE cObject can iterate over the array of records.
*
* Example TypoScript configuration:
*
* 10 = Evoweb\EwBloggy\DataProcessing\BlogPostProcessor
* 10 {
* as = post
* }
*
* 10 = blog-post
*
* where "as" means the variable to be containing the result-set from the DB query.
*/
readonly class BlogPostProcessor implements DataProcessorInterface
{
public function __construct(
protected PostRepository $postRepository,
) {
}
public function process(
ContentObjectRenderer $cObj,
array $contentObjectConfiguration,
array $processorConfiguration,
array $processedData
): array {
if (!$cObj->checkIf($processorConfiguration['if.'] ?? [])) {
return $processedData;
}
$targetVariableName = $cObj->stdWrapValue('as', $processorConfiguration, 'post');
$processedData[$targetVariableName] = $this->postRepository->findByUid((int)$processedData['data']['uid']);
return $processedData;
}
}