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
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* Formular unter einem Beitrag (z. B. Anmeldung zum Sommerfest). Ohne
|
||||
* Fremdschlüssel: Das Formular-Plugin ist optional.
|
||||
*/
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('news_posts', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('form_id')->nullable()->after('cover_path');
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('news_posts', fn (Blueprint $table) => $table->dropColumn('form_id'));
|
||||
}
|
||||
};
|
||||
|
|
@ -20,6 +20,7 @@ const props = defineProps({
|
|||
categories: { type: Array, required: true },
|
||||
canPublishWithoutCategory: { type: Boolean, default: false },
|
||||
canDelete: { type: Boolean, default: false },
|
||||
forms: { type: Array, default: () => [] },
|
||||
});
|
||||
|
||||
const page = usePage();
|
||||
|
|
@ -41,6 +42,7 @@ const form = useForm({
|
|||
remove_cover: false,
|
||||
is_featured: props.post?.is_featured ?? false,
|
||||
published_at: localValue(props.post?.published_at),
|
||||
form_id: props.post?.form_id ?? null,
|
||||
action: 'draft',
|
||||
});
|
||||
|
||||
|
|
@ -88,6 +90,7 @@ function submit(action) {
|
|||
...data,
|
||||
published_at: data.published_at ? new Date(data.published_at).toISOString() : null,
|
||||
category_id: data.category_id ? Number(data.category_id) : null,
|
||||
form_id: data.form_id ? Number(data.form_id) : '',
|
||||
...(props.post ? { _method: 'put' } : {}),
|
||||
})).post(props.post ? `/redaktion/neuigkeiten/${props.post.id}` : '/redaktion/neuigkeiten', {
|
||||
forceFormData: true,
|
||||
|
|
@ -205,6 +208,12 @@ const scheduled = computed(() => form.published_at && new Date(form.published_at
|
|||
</div>
|
||||
</Panel>
|
||||
|
||||
<Panel v-if="forms.length" title="Formular">
|
||||
<FormField id="form_id" label="Formular unter dem Beitrag" :error="form.errors.form_id" hint="Z. B. Anmeldung zum Sommerfest oder Rückmeldung. Formulare legt die Redaktion unter „Formulare“ an.">
|
||||
<NativeSelect id="form_id" v-model="form.form_id" :options="forms" placeholder="– kein Formular –" />
|
||||
</FormField>
|
||||
</Panel>
|
||||
|
||||
<Panel title="Titelbild">
|
||||
<div class="grid gap-3">
|
||||
<div v-if="coverPreview" class="relative overflow-hidden rounded-md border">
|
||||
|
|
|
|||
|
|
@ -6,12 +6,14 @@ import CategoryLabel from '../components/CategoryLabel.vue';
|
|||
import NewsCard from '../components/NewsCard.vue';
|
||||
import PersonAvatar from '@/components/PersonAvatar.vue';
|
||||
import AppLayout from '@/layouts/AppLayout.vue';
|
||||
import PageContent from '@/pagebuilder/PageContent.vue';
|
||||
import { formatDate } from '@/lib/format';
|
||||
|
||||
defineProps({
|
||||
post: { type: Object, required: true },
|
||||
related: { type: Object, required: true },
|
||||
editUrl: { type: String, default: null },
|
||||
form: { type: Object, default: null },
|
||||
});
|
||||
</script>
|
||||
|
||||
|
|
@ -46,6 +48,9 @@ defineProps({
|
|||
<img v-if="post.cover_url" :src="post.cover_url" :alt="post.title" class="mt-8 aspect-video w-full rounded-lg object-cover" />
|
||||
|
||||
<div class="prose prose-neutral mt-8 max-w-none prose-headings:tracking-tight prose-img:rounded-lg" v-html="post.body_html" />
|
||||
|
||||
<!-- Eingebundenes Formular (Pagebuilder-Block des Formular-Plugins) -->
|
||||
<PageContent v-if="form" :content="form" class="mt-10" />
|
||||
</article>
|
||||
|
||||
<section v-if="related.data.length" class="mx-auto mt-16 max-w-5xl">
|
||||
|
|
|
|||
|
|
@ -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