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
- 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>
48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?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;
|
||
}
|
||
}
|