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, ]); } } /** * The page the form was submitted from. The URL is generated through the site router in the * visitor's language, the same way AddReferrerFinisher does it, so it is the page's canonical * URL rather than the submit request with its form arguments attached. */ private function resolvePageContext(): array { if (false === isset($GLOBALS['TSFE']) || 0 === (int)$GLOBALS['TSFE']->id) { return []; } $pageUid = (int)$GLOBALS['TSFE']->id; $context = ['pageUid' => $pageUid]; try { $site = GeneralUtility::makeInstance(SiteFinder::class)->getSiteByPageId($pageUid); $context['pageUrl'] = (string)$site->getRouter()->generateUri($pageUid, [ '_language' => $GLOBALS['TSFE']->getLanguage(), ]); } 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; } }