Loheide-eu-mitarbeiterplatt.../app/Filament/Resources/NewsPosts/NewsPostResource.php
Friederich Loheide a36752e09a
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m8s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m12s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m12s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m5s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m6s
CI / Build-Artefakte aktuell (pull_request) Failing after 43s
Neuigkeiten und Termine (vorgezogen)
- Neuigkeiten mit Kategorien, Titelbild (WebP-Varianten), Lesezeit, geplanter
  Veröffentlichung und Hervorhebung; Text wird beim Speichern bereinigt
- Termine mit Ort, Online-Link, ganztägigen Terminen und .ics-Export
- Startseite nach Intranet-Vorbild: Slider, Neuigkeiten, Termine, Aktuelles
  aus den Bereichen; mobil in sinnvoller Reihenfolge
- Admin: Beiträge, Kategorien und Termine
- Bildverarbeitung für Shared Hosting: nur eine Vollbild-Kopie im Speicher,
  Speicherlimit bei Bedarf auf 256 MB angehoben (wie WordPress)
- Demo-Inhalte für die Entwicklung

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

156 lines
6.7 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 App\Filament\Resources\NewsPosts;
use App\Filament\Resources\NewsPosts\Pages\CreateNewsPost;
use App\Filament\Resources\NewsPosts\Pages\EditNewsPost;
use App\Filament\Resources\NewsPosts\Pages\ListNewsPosts;
use App\Models\NewsPost;
use BackedEnum;
use Filament\Actions\Action;
use Filament\Actions\DeleteAction;
use Filament\Actions\EditAction;
use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Resources\Resource;
use Filament\Schemas\Components\Section;
use Filament\Schemas\Schema;
use Filament\Support\Icons\Heroicon;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\ImageColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;
use UnitEnum;
class NewsPostResource extends Resource
{
protected static ?string $model = NewsPost::class;
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedNewspaper;
protected static string|UnitEnum|null $navigationGroup = 'Inhalte';
protected static ?int $navigationSort = 1;
protected static ?string $modelLabel = 'Beitrag';
protected static ?string $pluralModelLabel = 'Neuigkeiten';
protected static ?string $slug = 'neuigkeiten';
protected static ?string $recordTitleAttribute = 'title';
public static function form(Schema $schema): Schema
{
return $schema
->columns(3)
->components([
Section::make('Beitrag')
->columnSpan(2)
->schema([
TextInput::make('title')->label('Titel')->required()->maxLength(160),
Textarea::make('teaser')
->label('Kurztext')
->helperText('Erscheint in Listen und auf der Startseite. 1–2 Sätze.')
->rows(2)
->maxLength(300),
RichEditor::make('body')
->label('Text')
->toolbarButtons([
['bold', 'italic', 'underline', 'link'],
['h2', 'h3'],
['bulletList', 'orderedList', 'blockquote'],
['attachFiles', 'table'],
['undo', 'redo'],
])
->fileAttachmentsDisk('uploads')
->fileAttachmentsDirectory('news/inline')
->fileAttachmentsVisibility('public')
->fileAttachmentsAcceptedFileTypes(['image/jpeg', 'image/png', 'image/webp'])
->fileAttachmentsMaxSize(8 * 1024),
]),
Section::make('Veröffentlichung')
->columnSpan(1)
->schema([
Select::make('category_id')
->label('Kategorie')
->relationship('category', 'name')
->preload()
->searchable(),
DateTimePicker::make('published_at')
->label('Veröffentlichen am')
->helperText('Leer lassen = Entwurf. Ein Datum in der Zukunft plant den Beitrag.')
->seconds(false)
->native(false)
->displayFormat('d.m.Y H:i'),
Toggle::make('is_featured')
->label('Auf der Startseite hervorheben')
->helperText('Hervorgehobene Beiträge mit Titelbild erscheinen groß im Slider.'),
FileUpload::make('cover_path')
->label('Titelbild')
->helperText('Querformat, mindestens 1600 × 900 Pixel.')
->image()
->disk('uploads')
->directory('news')
->visibility('public')
->imageAspectRatio('16:9')
->automaticallyCropImagesToAspectRatio()
->maxSize(10 * 1024),
]),
]);
}
public static function table(Table $table): Table
{
return $table
->defaultSort('created_at', 'desc')
->columns([
ImageColumn::make('cover_path')->label('')->disk('uploads')->width(80)->height(45),
TextColumn::make('title')->label('Titel')->searchable()->limit(60)->weight('medium'),
TextColumn::make('category.name')->label('Kategorie')->badge()->color('gray'),
TextColumn::make('status')
->label('Status')
->badge()
->state(fn (NewsPost $record) => match (true) {
$record->published_at === null => 'Entwurf',
$record->published_at->isFuture() => 'Geplant',
default => 'Veröffentlicht',
})
->color(fn (string $state) => match ($state) {
'Veröffentlicht' => 'success',
'Geplant' => 'warning',
default => 'gray',
}),
IconColumn::make('is_featured')->label('Hervorgehoben')->boolean()->trueIcon(Heroicon::Star)->falseIcon(false)->trueColor('warning'),
TextColumn::make('published_at')->label('Veröffentlicht')->dateTime('d.m.Y H:i')->sortable(),
])
->filters([
SelectFilter::make('category_id')->label('Kategorie')->relationship('category', 'name'),
])
->recordActions([
Action::make('view')
->label('Ansehen')
->icon(Heroicon::OutlinedEye)
->url(fn (NewsPost $record) => route('news.show', $record))
->openUrlInNewTab()
->visible(fn (NewsPost $record) => $record->isPublished()),
EditAction::make(),
DeleteAction::make(),
]);
}
public static function getPages(): array
{
return [
'index' => ListNewsPosts::route('/'),
'create' => CreateNewsPost::route('/neu'),
'edit' => EditNewsPost::route('/{record}/bearbeiten'),
];
}
}