2020-11-27 23:10:46 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-01-25 16:02:17 +01:00
|
|
|
namespace SkillDisplay\SkilldisplayContent;
|
2020-11-27 23:10:46 +01:00
|
|
|
|
|
|
|
use SkillDisplay\PHPToolKit\Entity\Campaign;
|
2021-01-29 16:40:15 +01:00
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility;
|
2020-11-27 23:10:46 +01:00
|
|
|
|
|
|
|
class TcaEnhancer
|
|
|
|
{
|
2023-07-06 16:39:52 +02:00
|
|
|
private CampaignsFactory $campaignsFactory;
|
2021-01-22 11:29:38 +01:00
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
CampaignsFactory $campaignsFactory
|
|
|
|
) {
|
|
|
|
$this->campaignsFactory = $campaignsFactory;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCampaignsForTCA(array &$params): void
|
2020-11-27 23:10:46 +01:00
|
|
|
{
|
|
|
|
$params['items'] = [
|
|
|
|
['', 0],
|
|
|
|
];
|
|
|
|
|
2021-02-02 10:16:24 +01:00
|
|
|
$pid = $this->resolvePid($params['row']);
|
2021-01-29 16:40:15 +01:00
|
|
|
if ($pid > 0) {
|
2023-07-06 18:34:18 +02:00
|
|
|
try {
|
|
|
|
$campaigns = $this->campaignsFactory->createFromPageUid($pid)->getForUser();
|
|
|
|
} catch (\InvalidArgumentException $e) {
|
|
|
|
// ignore missing API key exception
|
|
|
|
if ($e->getCode() !== 1688660942) {
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2021-01-29 16:40:15 +01:00
|
|
|
/** @var Campaign $campaign */
|
|
|
|
foreach ($campaigns as $campaign) {
|
|
|
|
$params['items'][] = [
|
|
|
|
$campaign->getTitle(),
|
|
|
|
$campaign->getId(),
|
|
|
|
];
|
|
|
|
}
|
2020-11-27 23:10:46 +01:00
|
|
|
}
|
|
|
|
}
|
2021-02-02 10:16:24 +01:00
|
|
|
|
|
|
|
protected function resolvePid(array $row): ?int
|
|
|
|
{
|
|
|
|
return BackendUtility::getTSconfig_pidValue('tt_content', $row['uid'], $row['pid']);
|
|
|
|
}
|
2020-11-27 23:10:46 +01:00
|
|
|
}
|