Files
typo3-13/packages/ep_theme/Classes/Form/ApplicationApiFinisher.php
frommeandClaude Opus 5.5 b51fa4ddad refactor: PHP 8.5 language features via Rector
rector.php gets the PHP sets up to 8.5. Mostly constructor promotion with
readonly properties, typed class constants, ??=, arrow functions,
str_contains/str_starts_with, catch without unused variables, array_any
and #[\Override] on overridden properties; array_key_exists() keys are
cast to string (null keys are deprecated in PHP 8.5). Long promoted
constructor signatures are wrapped one parameter per line.

Checked locally: a crawl of ~1,900 frontend URLs over all sites and the
backchannel APIs (/api/hotel, /api/product, content feed manifest and
records of every type) render the same as before.

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

75 lines
2.7 KiB
PHP

<?php
namespace EP\EpTheme\Form;
use EP\EpProducts\EpTeam\ApiClient;
use TYPO3\CMS\Core\Routing\PageArguments;
use TYPO3\CMS\Core\Site\Entity\Site;
/**
* Sends job applications to MyE&P Team (POST /api/application-forms).
*/
class ApplicationApiFinisher extends AbstractMappedFinisher
{
public function __construct(private readonly ApiClient $apiClient) {}
protected function executeInternal()
{
try {
$payload = $this->buildPayload();
if ([] === $payload) {
$this->logWarning('Application form API finisher skipped: the mapping produced no values.');
return;
}
$formDefinition = $this->finisherContext->getFormRuntime()->getFormDefinition();
$formLabel = trim($formDefinition->getLabel());
$payload['form'] = $formDefinition->getIdentifier();
// The name the editor gave the form, so the receiving side can label a submission
// without keeping a list of identifiers. Taken from the definition rather than
// through TranslationService: a translated label would differ per site language.
$payload['formLabel'] = '' !== $formLabel ? $formLabel : $formDefinition->getIdentifier();
$payload['submittedAt'] = new \DateTimeImmutable()->format(\DateTimeInterface::ATOM);
$payload = array_merge($payload, $this->resolvePageContext());
$payload['details'] = $this->buildLabeledValues();
$this->apiClient->submitApplicationForm($payload);
} catch (\Throwable $e) {
$this->logWarning('Application form API finisher request failed.', [
'exception' => $e,
]);
}
}
private function resolvePageContext(): array
{
$request = $this->finisherContext->getRequest();
$routing = $request->getAttribute('routing');
if (!$routing instanceof PageArguments) {
return [];
}
$pageUid = $routing->getPageId();
$context = ['pageUid' => $pageUid];
try {
/** @var Site $site */
$site = $request->getAttribute('site');
// The page itself, not the form page type the submission was posted to
$context['pageUrl'] = (string)$site->getRouter()->generateUri($pageUid, [
'_language' => $request->getAttribute('language'),
]);
} catch (\Throwable $e) {
// An unroutable page must not cost the submission, so the uid is sent without a URL.
$this->logWarning('Application form API finisher could not resolve the page URL.', [
'pageUid' => $pageUid,
'exception' => $e,
]);
}
return $context;
}
}