Formular-Infrastruktur: Contact/Demo/Helpdesk mit E-Mail- und Salesforce-Delivery, JSON-Renderer-Erweiterungen, Crop-Variants
Build-Artefakte in public/_frontend/assets nicht enthalten.
This commit is contained in:
1 parent
eae40f4286
commit
a739dd8fe3
51 files changed
+1598
-303
No files matched your search
+108
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Evomedien\Vitec\UserFunc;
|
||||
|
||||
use Doctrine\DBAL\ParameterType;
|
||||
use Evomedien\Vitec\Forms\FormDefinitions;
|
||||
use TYPO3\CMS\Core\Attribute\AsAllowedCallable;
|
||||
use TYPO3\CMS\Core\Database\ConnectionPool;
|
||||
use TYPO3\CMS\Core\Service\FlexFormService;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* UserFunc: render ONE of the VITEC form plugins as JSON (headless).
|
||||
* Serves vitec_contactform, vitec_demoform and vitec_helpdeskform — the
|
||||
* CType picks the definition from FormDefinitions.
|
||||
*
|
||||
* Output under content.form:
|
||||
* { "formKey": "contact", "title": "…", "endpoint": "/api/vitec/form/contact",
|
||||
* "honeypot": "_website", "fields": [ … ] }
|
||||
*
|
||||
* The React frontend renders the fields generically and POSTs JSON to the
|
||||
* endpoint (handled by FormSubmissionMiddleware). Exception-safe.
|
||||
*/
|
||||
class FormsJsonRenderer
|
||||
{
|
||||
#[AsAllowedCallable]
|
||||
public function render(string $content, array $conf): string
|
||||
{
|
||||
$row = is_array($this->cObj->data ?? null) ? $this->cObj->data : null;
|
||||
if ($row && isset(FormDefinitions::CTYPE_MAP[(string)($row['CType'] ?? '')])) {
|
||||
return $this->renderForRecord($row);
|
||||
}
|
||||
|
||||
$pageId = 0;
|
||||
$request = $GLOBALS['TYPO3_REQUEST'] ?? null;
|
||||
if ($request !== null) {
|
||||
$pageInfo = $request->getAttribute('frontend.page.information');
|
||||
if ($pageInfo !== null) {
|
||||
$pageId = (int)$pageInfo->getId();
|
||||
}
|
||||
}
|
||||
if ($pageId <= 0) {
|
||||
$pageId = (int)($GLOBALS['TSFE']->id ?? 0);
|
||||
}
|
||||
if ($pageId <= 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$qb = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
|
||||
$ces = $qb
|
||||
->select('*')
|
||||
->from('tt_content')
|
||||
->where(
|
||||
$qb->expr()->eq('pid', $qb->createNamedParameter($pageId, ParameterType::INTEGER)),
|
||||
$qb->expr()->in('CType', $qb->createNamedParameter(
|
||||
array_keys(FormDefinitions::CTYPE_MAP),
|
||||
\TYPO3\CMS\Core\Database\Connection::PARAM_STR_ARRAY
|
||||
)),
|
||||
$qb->expr()->eq('deleted', 0),
|
||||
$qb->expr()->eq('hidden', 0)
|
||||
)
|
||||
->executeQuery()
|
||||
->fetchAllAssociative();
|
||||
|
||||
if (empty($ces)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $this->renderForRecord($ces[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string,mixed> $contentElement
|
||||
*/
|
||||
public function renderForRecord(array $contentElement): string
|
||||
{
|
||||
try {
|
||||
$formKey = FormDefinitions::CTYPE_MAP[(string)($contentElement['CType'] ?? '')] ?? '';
|
||||
$definition = FormDefinitions::get($formKey);
|
||||
if ($definition === null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$flexFormService = GeneralUtility::makeInstance(FlexFormService::class);
|
||||
$flexFormData = $flexFormService->convertFlexFormContentToArray($contentElement['pi_flexform'] ?? '');
|
||||
$settings = $flexFormData['settings'] ?? [];
|
||||
$debugMode = (bool)($settings['debug'] ?? false);
|
||||
|
||||
$response = [
|
||||
'formKey' => $definition['formKey'],
|
||||
'title' => $definition['title'],
|
||||
'endpoint' => '/api/vitec/form/' . $definition['formKey'],
|
||||
'honeypot' => FormDefinitions::HONEYPOT_FIELD,
|
||||
'fields' => $definition['fields'],
|
||||
];
|
||||
|
||||
if ($debugMode) {
|
||||
$response['debug'] = ['settings' => $settings];
|
||||
}
|
||||
|
||||
return (string)json_encode($response);
|
||||
} catch (\Throwable $e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user