Formulare: visueller Baukasten, CSV-Auswahl, Einbindung unter Beiträgen
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
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>
This commit is contained in:
parent
11123fecc0
commit
435960725d
139 changed files with 1735 additions and 432 deletions
|
|
@ -27,6 +27,7 @@ use Illuminate\Database\Eloquent\Builder;
|
|||
use Inhaus\Plugins\News\Filament\Resources\NewsPosts\Pages\CreateNewsPost;
|
||||
use Inhaus\Plugins\News\Filament\Resources\NewsPosts\Pages\EditNewsPost;
|
||||
use Inhaus\Plugins\News\Filament\Resources\NewsPosts\Pages\ListNewsPosts;
|
||||
use Inhaus\Plugins\News\FormEmbed;
|
||||
use Inhaus\Plugins\News\Models\NewsCategory;
|
||||
use Inhaus\Plugins\News\Models\NewsPost;
|
||||
use Inhaus\Plugins\News\Policies\NewsPostPolicy;
|
||||
|
|
@ -106,6 +107,12 @@ class NewsPostResource extends Resource
|
|||
->label('Auf der Startseite hervorheben')
|
||||
->disabled(fn (Get $get) => ! static::canPublishIn($get('category_id')))
|
||||
->helperText('Hervorgehobene Beiträge mit Titelbild erscheinen groß im Slider.'),
|
||||
Select::make('form_id')
|
||||
->label('Formular unter dem Beitrag')
|
||||
->helperText('Z. B. Anmeldung oder Rückmeldung zum Beitrag.')
|
||||
->options(fn () => FormEmbed::options())
|
||||
->visible(fn () => FormEmbed::available())
|
||||
->searchable(),
|
||||
FileUpload::make('cover_path')
|
||||
->label('Titelbild')
|
||||
->helperText('Querformat, mindestens 1600 × 900 Pixel.')
|
||||
|
|
|
|||
48
plugins-core/news/src/FormEmbed.php
Normal file
48
plugins-core/news/src/FormEmbed.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?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;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ use App\Http\Controllers\Controller;
|
|||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Inhaus\Plugins\News\FormEmbed;
|
||||
use Inhaus\Plugins\News\Http\Resources\NewsPostResource;
|
||||
use Inhaus\Plugins\News\Models\NewsCategory;
|
||||
use Inhaus\Plugins\News\Models\NewsPost;
|
||||
|
|
@ -53,6 +54,7 @@ class NewsController extends Controller
|
|||
] : null,
|
||||
],
|
||||
'editUrl' => request()->user()->can('update', $post) ? route('news.editor.edit', $post) : null,
|
||||
'form' => FormEmbed::render($post->form_id, request()->user()),
|
||||
'related' => NewsPostResource::collection(
|
||||
NewsPost::query()
|
||||
->published()
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ use Illuminate\Validation\Rules\File;
|
|||
use Illuminate\Validation\ValidationException;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
use Inhaus\Plugins\News\FormEmbed;
|
||||
use Inhaus\Plugins\News\Models\NewsCategory;
|
||||
use Inhaus\Plugins\News\Models\NewsPost;
|
||||
use Inhaus\Plugins\News\NewsWorkflow;
|
||||
|
|
@ -125,6 +126,7 @@ class NewsEditorController extends Controller
|
|||
'remove_cover' => ['boolean'],
|
||||
'is_featured' => ['boolean'],
|
||||
'published_at' => ['nullable', 'date'],
|
||||
'form_id' => ['nullable', 'integer', Rule::in(array_map('intval', array_keys(FormEmbed::options())))],
|
||||
'action' => ['required', Rule::in(['draft', 'submit', 'publish'])],
|
||||
], ['category_id.in' => 'In dieser Kategorie dürfen Sie keine Beiträge schreiben.'], ['category_id' => 'Kategorie', 'title' => 'Titel']);
|
||||
|
||||
|
|
@ -139,6 +141,7 @@ class NewsEditorController extends Controller
|
|||
'teaser' => $data['teaser'] ?? null,
|
||||
'body' => $data['body'] ?? null,
|
||||
'category_id' => $data['category_id'] ?? null,
|
||||
'form_id' => FormEmbed::available() ? ($data['form_id'] ?? null) : $post->form_id,
|
||||
]);
|
||||
|
||||
if ($canPublish) {
|
||||
|
|
@ -209,6 +212,7 @@ class NewsEditorController extends Controller
|
|||
'is_published' => $post->isPublished(),
|
||||
'url' => $post->isPublished() ? route('news.show', $post) : null,
|
||||
'review_note' => $post->review_note,
|
||||
'form_id' => $post->form_id,
|
||||
'author' => $post->author?->name,
|
||||
] : null,
|
||||
'categories' => $categories->map(fn (NewsCategory $c) => [
|
||||
|
|
@ -217,6 +221,7 @@ class NewsEditorController extends Controller
|
|||
'can_publish' => $this->policy->publish($user, $c->id),
|
||||
]),
|
||||
'canPublishWithoutCategory' => $user->can('news.manage'),
|
||||
'forms' => collect(FormEmbed::options())->map(fn ($title, $id) => ['value' => (int) $id, 'label' => $title])->values(),
|
||||
'canDelete' => $post && $user->can('delete', $post) && ($post->status !== NewsPost::PUBLISHED || $this->policy->publish($user, $post->category_id)),
|
||||
]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ use Inhaus\Plugins\News\Database\Factories\NewsPostFactory;
|
|||
|
||||
#[Fillable([
|
||||
'category_id', 'author_id', 'title', 'slug', 'teaser', 'body',
|
||||
'cover_path', 'is_featured', 'published_at',
|
||||
'cover_path', 'is_featured', 'published_at', 'form_id',
|
||||
])]
|
||||
class NewsPost extends Model
|
||||
{
|
||||
|
|
@ -80,6 +80,7 @@ class NewsPost extends Model
|
|||
'is_featured' => 'boolean',
|
||||
'published_at' => 'datetime',
|
||||
'submitted_at' => 'datetime',
|
||||
'form_id' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue