Files
typo3-13/packages/ep_theme/Classes/DataProcessing/ContextProcessor.php
T
frommeandClaude Opus 5.5 ecd5ea66c5 refactor: type declarations via Rector
rector.php gets the typeDeclarations set: return types (void, array,
unions) where the code proves them, typed closures and arrow functions,
typed properties from constructors and assignments in the DTOs.

Skipped: rules that infer scalar or array parameter types from call
sites or docblocks, and the removal of casts the docblocks call
redundant. Values from the database, form input and the import feeds
arrive as strings and would throw instead of being converted (e.g. the
(int) cast of the newsletter list ids stays).

Checked locally: cache warmup, frontend crawl (~1,900 URLs), the
backchannel APIs and the newsletter form validation behave as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-26 11:21:12 +01:00

87 lines
2.4 KiB
PHP

<?php
namespace EP\EpTheme\DataProcessing;
use EP\EpProducts\Traits\DbConnectionTrait;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
class ContextProcessor implements DataProcessorInterface
{
use DbConnectionTrait;
/**
* @return array
* @throws \Doctrine\DBAL\DBALException
*/
public function process(
ContentObjectRenderer $cObj,
array $contentObjectConfiguration,
array $processorConfiguration,
array $processedData
) {
$data = $cObj->data;
$processedData['context'] = [];
$countryUid = (int) $data['tx_eptheme_context_country'];
if ($countryUid > 0) {
$processedData['context']['country'] = $this->getContextRecord($countryUid, 'tx_epproducts_domain_model_country');
}
$regionUid = (int) $data['tx_eptheme_context_region'];
if ($regionUid > 0) {
$processedData['context']['region'] = $this->getContextRecord($regionUid, 'tx_epproducts_domain_model_region');
}
if ($data['tx_eptheme_context_pacode'] ?? null) {
$processedData['context']['paCode'] = $data['tx_eptheme_context_pacode'];
} elseif ($paCode = $this->getPaCodeFromRequest()) {
$processedData['context']['paCode'] = $paCode;
}
return $processedData;
}
/**
* @return string
*/
private function getPaCodeFromRequest(): string|array
{
$currentUri = GeneralUtility::getIndpEnv('REQUEST_URI');
$query = parse_url($currentUri, \PHP_URL_QUERY);
if (!$query) {
return '';
}
parse_str($query, $items);
if (array_key_exists('pa', $items)) {
return $items['pa'];
}
return '';
}
/**
* @param int $uid
* @param string $table
* @return array
* @throws \Doctrine\DBAL\DBALException
*/
private function getContextRecord($uid, $table): array|false
{
$qb = $this->getDbConnection()->createQueryBuilder();
$query = $qb
->select('*')
->from($table)
->where('uid = :uid')
->andWhere('deleted = 0')
->andWhere('hidden = 0')
->setParameter('uid', $uid)
;
return $query->executeQuery()->fetchAssociative();
}
}