Loheide-eu-mitarbeiterplatt.../plugins-core/news/src/FormEmbed.php
Friederich Loheide 435960725d
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m59s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m5s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m11s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m6s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 3m2s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 3m3s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m37s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m39s
CI / Build-Artefakte aktuell (pull_request) Failing after 52s
Formulare: visueller Baukasten, CSV-Auswahl, Einbindung unter Beiträgen
- Visueller Formularbaukasten im Portal (/redaktion/formulare/{id}): Formular
  wie ausgefüllt, Bezeichnungen/Optionen/Hinweise direkt bearbeiten, Ziehen
  und Ablegen aus der Palette, Pflicht/Breite in der Werkzeugleiste,
  Einstellungen und Bedingungen in der Seitenleiste, Vorschau mit Bedingungen
- Admin: Felder-Reiter führt in den Baukasten; nach dem Anlegen direkt dorthin
- CSV: in der Formularliste, im Redaktionsbereich und für ausgewählte Einsendungen
- Neuigkeiten: Formular unter dem Beitrag (über den Pagebuilder-Block, ohne
  Abhängigkeit vom Formular-Plugin)
- Kein Menüpunkt „Formulare“ im Portal; Redaktionsbereich „Formulare“

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 09:35:39 +00:00

48 lines
1.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Inhaus\Plugins\News;
use App\Models\User;
use App\Pagebuilder\Blocks;
use App\Pagebuilder\Content;
/**
* Formular unter einem Beitrag – über den Pagebuilder-Block „forms.form“,
* damit die Neuigkeiten nicht vom Formular-Plugin abhängen.
*/
final class FormEmbed
{
public const BLOCK = 'forms.form';
public static function available(): bool
{
return app(Blocks::class)->get(self::BLOCK) !== null;
}
/**
* @return array<string, string> ID => Titel
*/
public static function options(): array
{
$field = collect(app(Blocks::class)->get(self::BLOCK)?->fields ?? [])->first(fn ($f) => $f->name === 'form');
return $field ? collect($field->toArray()['choices'] ?? [])->pluck('label', 'value')->all() : [];
}
/**
* Anzeigefertiger Inhalt (wie eine Pagebuilder-Seite mit einem Block) oder null.
*
* @return array<string, mixed>|null
*/
public static function render(?int $formId, ?User $user): ?array
{
if (! $formId || ! self::available()) {
return null;
}
$content = app(Content::class);
$rendered = $content->render($content->sanitize(['blocks' => [['type' => self::BLOCK, 'data' => ['form' => (string) $formId, 'show_title' => true]]]]), $user);
return $rendered['blocks'] === [] ? null : $rendered;
}
}