DEV CommiDEV Committ

This commit is contained in:
khaccount committed 2026-07-01 10:34:48 +02:00
1 parent 4541c58fe7
commit c6759186cb
145 files changed
+2742 -579

No files matched your search

@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace Evomedien\Vitec\Backend\FormEngine;
use TYPO3\CMS\Backend\Form\AbstractNode;
use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction;
/**
* FormEngine fieldWizard rendered below the product `structureddata` field.
* Adds a "generate" button that, on click, asks the backend AJAX endpoint to
* build the JSON-LD for the current product and writes it into the field.
*
* Registered as nodeName "structuredDataGenerator" (see ext_localconf.php) and
* attached via TCA fieldWizard on tx_vitec_domain_model_product.structureddata.
*
* The button carries data-vitec-sd-generate (so the self-initializing JS module
* binds via event delegation) and data-field-name = the textarea's form name
* (itemFormElName — the reliable field reference; itemFormElID is empty in this
* context). The JS resolves the textarea via [name="…"] with a DOM fallback.
*
* The actual generation lives server-side in
* {@see \Evomedien\Vitec\Controller\Backend\StructuredDataController}.
*/
final class StructuredDataGeneratorWizard extends AbstractNode
{
public function render(): array
{
$result = $this->initializeResultArray();
$row = $this->data['databaseRow'] ?? [];
$rawUid = $row['uid'] ?? null;
$uid = (int)$rawUid;
$isNew = !is_numeric($rawUid) || $uid <= 0;
$itemName = (string)($this->data['parameterArray']['itemFormElName'] ?? '');
$buttonId = 'vitec-sd-generate-' . md5($itemName);
$hint = $isNew
? '<span class="text-warning">Bitte das Produkt zuerst speichern, dann steht die Generierung zur Verfügung.</span>'
: 'Erzeugt das JSON-LD aus den gespeicherten Produktdaten und überschreibt den Feldinhalt.';
$html = [];
$html[] = '<div class="vitec-sd-generator" style="margin-top:.5rem">';
$html[] = sprintf(
'<button type="button" class="btn btn-default btn-sm" id="%s" data-vitec-sd-generate="1" data-uid="%d" data-field-name="%s"%s>',
htmlspecialchars($buttonId),
$uid,
htmlspecialchars($itemName),
$isNew ? ' disabled' : ''
);
$html[] = 'Structured Data generieren';
$html[] = '</button>';
$html[] = '<div class="form-text">' . $hint . '</div>';
$html[] = '</div>';
$result['html'] = implode("\n", $html);
$result['javaScriptModules'][] = JavaScriptModuleInstruction::create(
'@evomedien/vitec/structured-data-generator.js'
);
return $result;
}
}