Files
typo3-13/packages/ep_theme/Classes/DataProcessing/ContextProcessor.php
T
frommeandClaude Opus 5.5 f4556ee75c refactor: remove dead code via Rector
rector.php gets the deadCode set: @param/@return/@var tags that only
repeat native types, === true comparisons, three unused constructor
dependencies (DateService, ProductDataService, AjaxWatchlistController),
the unused reseller lookup in ContextProcessor and an always-false check
in AbstractMappedFinisher (trimExplode with removeEmpty never yields an
empty remote name).

Checked locally: frontend crawl (~1,900 URLs) and the backchannel APIs
render the same as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-26 11:10:20 +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()
{
$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)
{
$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();
}
}