Veröffentliche fachliche Säulen als Themenbereiche der Website.
Dieselbe Liste trägt die öffentliche Seite. Medien bleiben privat, Seiten können mehreren Säulen zugeordnet sein. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
af85a94cd5
commit
8cd382c357
21 files changed
+379
-13
No files matched your search
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use App\Domain\Cms\Page;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
@@ -9,10 +11,40 @@ class Pillar extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'slug',
|
||||
'public_summary',
|
||||
'sort_order',
|
||||
'published_at',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'published_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
|
||||
public function elements(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(ContentElement::class);
|
||||
}
|
||||
|
||||
public function pages(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Page::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Builder<Pillar> $query
|
||||
* @return Builder<Pillar>
|
||||
*/
|
||||
public function scopePublished(Builder $query): Builder
|
||||
{
|
||||
return $query->whereNotNull('published_at')->orderBy('sort_order')->orderBy('name');
|
||||
}
|
||||
|
||||
public function publicUrl(): string
|
||||
{
|
||||
return route('theme', ['slug' => $this->slug]);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace App\Domain\Catalog;
|
||||
|
||||
use App\Domain\Cms\Page;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class PillarService
|
||||
{
|
||||
public function create(string $name): Pillar
|
||||
@@ -12,10 +15,13 @@ public function create(string $name): Pillar
|
||||
throw new DomainRuleException('Diese fachliche Säule gibt es schon.');
|
||||
}
|
||||
|
||||
return Pillar::query()->create(['name' => $name]);
|
||||
return Pillar::query()->create([
|
||||
'name' => $name,
|
||||
'slug' => $this->uniqueSlug(Str::slug($name, '-', 'de')),
|
||||
]);
|
||||
}
|
||||
|
||||
public function rename(Pillar $pillar, string $name): void
|
||||
public function present(Pillar $pillar, string $name, string $slug, ?string $summary, bool $published, int $sortOrder): void
|
||||
{
|
||||
$name = $this->name($name);
|
||||
|
||||
@@ -23,14 +29,19 @@ public function rename(Pillar $pillar, string $name): void
|
||||
throw new DomainRuleException('Diese fachliche Säule gibt es schon.');
|
||||
}
|
||||
|
||||
$summary = trim((string) $summary);
|
||||
$pillar->name = $name;
|
||||
$pillar->slug = $this->slug($slug, $pillar->id);
|
||||
$pillar->public_summary = $summary === '' ? null : $summary;
|
||||
$pillar->sort_order = max(0, $sortOrder);
|
||||
$pillar->published_at = $published ? ($pillar->published_at ?? now()) : null;
|
||||
$pillar->save();
|
||||
}
|
||||
|
||||
public function delete(Pillar $pillar): void
|
||||
{
|
||||
if ($pillar->elements()->exists()) {
|
||||
throw new DomainRuleException('Eine Säule mit zugeordneten Medien wird nicht gelöscht.');
|
||||
if ($pillar->elements()->exists() || $pillar->pages()->exists()) {
|
||||
throw new DomainRuleException('Eine Säule mit zugeordneten Medien oder Seiten wird nicht gelöscht.');
|
||||
}
|
||||
|
||||
$pillar->delete();
|
||||
@@ -40,6 +51,23 @@ public function delete(Pillar $pillar): void
|
||||
* @param list<int> $pillarIds
|
||||
*/
|
||||
public function assign(ContentElement $element, array $pillarIds): void
|
||||
{
|
||||
$element->pillars()->sync($this->ids($pillarIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $pillarIds
|
||||
*/
|
||||
public function assignPages(Page $page, array $pillarIds): void
|
||||
{
|
||||
$page->pillars()->sync($this->ids($pillarIds));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $pillarIds
|
||||
* @return list<int>
|
||||
*/
|
||||
private function ids(array $pillarIds): array
|
||||
{
|
||||
$ids = array_values(array_unique(array_map(intval(...), $pillarIds)));
|
||||
|
||||
@@ -47,7 +75,42 @@ public function assign(ContentElement $element, array $pillarIds): void
|
||||
throw new DomainRuleException('Eine fachliche Säule fehlt.');
|
||||
}
|
||||
|
||||
$element->pillars()->sync($ids);
|
||||
return $ids;
|
||||
}
|
||||
|
||||
private function slug(string $slug, ?int $ignoreId = null): string
|
||||
{
|
||||
$slug = Str::slug($slug, '-', 'de');
|
||||
|
||||
if ($slug === '') {
|
||||
throw new DomainRuleException('Die öffentliche Adresse der Säule fehlt.');
|
||||
}
|
||||
|
||||
$existing = Pillar::query()->where('slug', $slug);
|
||||
|
||||
if ($ignoreId !== null) {
|
||||
$existing->whereKeyNot($ignoreId);
|
||||
}
|
||||
|
||||
if ($existing->exists()) {
|
||||
throw new DomainRuleException('Diese öffentliche Adresse ist schon vergeben.');
|
||||
}
|
||||
|
||||
return $slug;
|
||||
}
|
||||
|
||||
private function uniqueSlug(string $base): string
|
||||
{
|
||||
$base = $base !== '' ? $base : 'saeule';
|
||||
$slug = $base;
|
||||
$suffix = 2;
|
||||
|
||||
while (Pillar::query()->where('slug', $slug)->exists()) {
|
||||
$slug = $base.'-'.$suffix;
|
||||
$suffix++;
|
||||
}
|
||||
|
||||
return $slug;
|
||||
}
|
||||
|
||||
private function name(string $name): string
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Domain\Cms;
|
||||
|
||||
use App\Domain\Catalog\Pillar;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
@@ -42,4 +44,25 @@ public function publicUrl(): string
|
||||
{
|
||||
return $this->path === '/' ? url('/') : url($this->path);
|
||||
}
|
||||
|
||||
public function publicTitle(): string
|
||||
{
|
||||
$revision = $this->publishedRevision;
|
||||
$heading = collect($revision?->blocks ?? [])->firstWhere('type', 'heading');
|
||||
|
||||
if (is_string($revision?->seo_title) && $revision->seo_title !== '') {
|
||||
return $revision->seo_title;
|
||||
}
|
||||
|
||||
if (is_array($heading) && is_string($heading['heading'] ?? null) && $heading['heading'] !== '') {
|
||||
return $heading['heading'];
|
||||
}
|
||||
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
public function pillars(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Pillar::class)->orderBy('pillars.name');
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,14 @@
|
||||
|
||||
namespace App\Filament\Resources\Pages;
|
||||
|
||||
use App\Domain\Catalog\Pillar;
|
||||
use App\Domain\Cms\Blocks\BlockRegistry;
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Filament\Resources\Pages\Pages\CreatePage;
|
||||
use App\Filament\Resources\Pages\Pages\EditPage;
|
||||
use App\Filament\Resources\Pages\Pages\ListPages;
|
||||
use App\Filament\Resources\Pages\RelationManagers\RevisionsRelationManager;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Repeater;
|
||||
use Filament\Forms\Components\Select;
|
||||
@@ -48,6 +50,11 @@ public static function form(Schema $schema): Schema
|
||||
->label('SEO-Beschreibung')
|
||||
->maxLength(500)
|
||||
->columnSpanFull(),
|
||||
CheckboxList::make('pillars')
|
||||
->label('Fachliche Säulen')
|
||||
->options(fn (): array => Pillar::query()->orderBy('name')->pluck('name', 'id')->all())
|
||||
->helperText('Eine veröffentlichte Seite erscheint auf den gewählten Themenbereichen der Website. Eine Seite kann mehreren Säulen zugeordnet sein.')
|
||||
->columns(1),
|
||||
Repeater::make('blocks')
|
||||
->label('Bausteine')
|
||||
->schema([
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\Pages\Pages;
|
||||
|
||||
use App\Domain\Catalog\PillarService;
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PageService;
|
||||
use App\Filament\Resources\Pages\PageResource;
|
||||
@@ -49,6 +50,7 @@ protected function mutateFormDataBeforeFill(array $data): array
|
||||
$data['blocks'] = $revision?->blocks ?? [];
|
||||
$data['seo_title'] = $revision?->seo_title;
|
||||
$data['seo_description'] = $revision?->seo_description;
|
||||
$data['pillars'] = $this->record->pillars()->pluck('pillars.id')->all();
|
||||
|
||||
return $data;
|
||||
}
|
||||
@@ -63,6 +65,7 @@ protected function handleRecordUpdate(Model $record, array $data): Model
|
||||
$record->update([
|
||||
'path' => $service->normalizePath($data['path']),
|
||||
]);
|
||||
app(PillarService::class)->assignPages($record, array_map(intval(...), $data['pillars'] ?? []));
|
||||
|
||||
$service->saveRevision(
|
||||
$record,
|
||||
|
||||
@@ -42,11 +42,25 @@ protected function getHeaderActions(): array
|
||||
];
|
||||
}
|
||||
|
||||
protected function mutateFormDataBeforeFill(array $data): array
|
||||
{
|
||||
$data['published'] = $this->getRecord()->published_at !== null;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
protected function handleRecordUpdate(Model $record, array $data): Model
|
||||
{
|
||||
/** @var Pillar $record */
|
||||
try {
|
||||
app(PillarService::class)->rename($record, $data['name']);
|
||||
app(PillarService::class)->present(
|
||||
$record,
|
||||
(string) $data['name'],
|
||||
(string) ($data['slug'] ?? ''),
|
||||
$data['public_summary'] ?? null,
|
||||
(bool) ($data['published'] ?? false),
|
||||
(int) ($data['sort_order'] ?? 0),
|
||||
);
|
||||
} catch (DomainRuleException $exception) {
|
||||
Notification::make()->title($exception->getMessage())->danger()->send();
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class ListPillars extends ListRecords
|
||||
|
||||
public function getSubheading(): string|Htmlable|null
|
||||
{
|
||||
return 'Die fachlichen Säulen des Materials. Es können weitere hinzukommen. Ein Medium kann mehreren Säulen zugeordnet sein.';
|
||||
return 'Die fachlichen Säulen des Materials. Eine veröffentlichte Säule ist ein Themenbereich der Website. Ein Medium und eine Seite können mehreren Säulen zugeordnet sein.';
|
||||
}
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
|
||||
@@ -6,7 +6,9 @@
|
||||
use App\Filament\Resources\ContentElements\ContentElementResource;
|
||||
use App\Filament\Resources\Pillars\Pages\EditPillar;
|
||||
use App\Filament\Resources\Pillars\Pages\ListPillars;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
@@ -46,6 +48,12 @@ public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
TextInput::make('name')->label('Name')->required(),
|
||||
TextInput::make('slug')->label('Öffentliche Adresse')->required()
|
||||
->helperText('Ergibt die Seite /themen/adresse. Eine Änderung verschiebt die öffentliche Adresse.'),
|
||||
Textarea::make('public_summary')->label('Text für die Website')->rows(5)
|
||||
->helperText('Dieser Text erscheint auf der Website. Die zugeordneten Medien bleiben privat.'),
|
||||
TextInput::make('sort_order')->label('Reihenfolge')->numeric()->minValue(0)->required()->default(0),
|
||||
Toggle::make('published')->label('Auf der Website veröffentlichen'),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -53,6 +61,9 @@ public static function table(Table $table): Table
|
||||
{
|
||||
return $table->columns([
|
||||
TextColumn::make('name')->label('Name')->searchable(),
|
||||
TextColumn::make('public_state')->label('Website')->state(
|
||||
fn (Pillar $record): string => $record->published_at === null ? 'intern' : 'veröffentlicht'
|
||||
),
|
||||
TextColumn::make('elements_count')->counts('elements')->label('Medien'),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Domain\Catalog\Pillar;
|
||||
use App\Domain\Cms\Page;
|
||||
use App\Domain\Cms\PageRevision;
|
||||
use Illuminate\Contracts\View\View;
|
||||
@@ -31,9 +32,10 @@ public function preview(PageRevision $revision): View
|
||||
public function sitemap(): Response
|
||||
{
|
||||
$pages = Page::query()->whereNotNull('published_revision_id')->orderBy('path')->get();
|
||||
$themes = Pillar::query()->published()->get();
|
||||
|
||||
return response()
|
||||
->view('public.sitemap', ['pages' => $pages])
|
||||
->view('public.sitemap', ['pages' => $pages, 'themes' => $themes])
|
||||
->header('Content-Type', 'application/xml');
|
||||
}
|
||||
|
||||
@@ -50,6 +52,7 @@ private function render(Page $page, bool $preview, ?PageRevision $revision = nul
|
||||
'preview' => $preview,
|
||||
'documentTitle' => $revision->seo_title ?: ($heading['heading'] ?? config('app.name')),
|
||||
'documentDescription' => $revision->seo_description,
|
||||
'themes' => $page->path === '/' ? Pillar::query()->published()->get() : collect(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Domain\Catalog\Pillar;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class ThemeController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
return view('public.themes.index', [
|
||||
'themes' => Pillar::query()->published()->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(string $slug): View
|
||||
{
|
||||
$theme = Pillar::query()->published()->where('slug', $slug)->firstOrFail();
|
||||
$pages = $theme->pages()
|
||||
->whereNotNull('published_revision_id')
|
||||
->with('publishedRevision')
|
||||
->orderBy('path')
|
||||
->get();
|
||||
|
||||
return view('public.themes.show', [
|
||||
'theme' => $theme,
|
||||
'pages' => $pages,
|
||||
'documentDescription' => $this->description($theme),
|
||||
]);
|
||||
}
|
||||
|
||||
private function description(Pillar $theme): string
|
||||
{
|
||||
$summary = trim((string) $theme->public_summary);
|
||||
$summary = preg_replace('/\s+/', ' ', $summary) ?? '';
|
||||
|
||||
if (mb_strlen($summary) <= 160) {
|
||||
return $summary;
|
||||
}
|
||||
|
||||
return rtrim(mb_substr($summary, 0, 157)).'…';
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user