Seiten: Bausteine und Vorlagen (0.22.0)
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 5m0s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 5m0s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m50s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m33s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m11s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m46s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m24s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m33s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m17s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-27 07:48:02 +00:00
parent 8817727283
commit 2166a7e11a
129 changed files with 1381 additions and 267 deletions

View file

@ -16,6 +16,7 @@ use App\Support\Navigation;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Schedule;
use Inhaus\Plugins\Pages\Models\ContentSnippet;
use Inhaus\Plugins\Pages\Models\Page;
use Inhaus\Plugins\Pages\Models\PageFile;
use Inhaus\Plugins\Pages\Policies\PagePolicy;
@ -89,6 +90,16 @@ class PagesPlugin extends Plugin
fn (User $user) => EditorialPages::props($user),
);
$this->app->make(Editorial::class)->add(
'pages.snippets',
'Bausteine & Vorlagen',
'pages::EditorialSnippets',
25,
fn (User $user) => $user->can('pages.manage'),
fn (User $user) => $this->snippetList(),
);
$this->app->singleton(Snippets::class);
$this->registerBlocks($this->app->make(Blocks::class));
$this->registerMediaUsages($this->app->make(MediaUsages::class));
}
@ -126,10 +137,51 @@ class PagesPlugin extends Plugin
}, fn (callable $each) => Page::query()->chunkById(50, fn ($pages) => $pages->each($each)));
$usages->watch('pages', Page::class, ['content', 'draft', 'scheduled_content', 'title', 'draft_title', 'scheduled_title']);
$usages->add('snippets', 'Bausteine & Vorlagen', function (ContentSnippet $snippet) {
$entries = [];
foreach (ImagePaths::fromContent($snippet->content) as $context => $paths) {
$entries[] = ['context' => $context, 'label' => ContentSnippet::KINDS[$snippet->kind].': '.$snippet->name, 'url' => route('snippets.edit', $snippet, false), 'draft' => false, 'paths' => $paths];
}
return $entries;
}, fn (callable $each) => ContentSnippet::query()->chunkById(50, fn ($snippets) => $snippets->each($each)));
$usages->watch('snippets', ContentSnippet::class, ['content', 'name']);
}
/**
* @return array<string, mixed>
*/
private function snippetList(): array
{
$usages = $this->app->make(Snippets::class)->usages();
return ['snippets' => ContentSnippet::query()->with('editor:id,name')->orderBy('kind')->orderBy('name')->get()->map(fn (ContentSnippet $snippet) => [
'id' => $snippet->id,
'kind' => $snippet->kind,
'name' => $snippet->name,
'description' => $snippet->description,
'blocks' => count($snippet->content['blocks'] ?? []),
'usages' => $usages[$snippet->id] ?? [],
'edit_url' => route('snippets.edit', $snippet),
'updated_at' => $snippet->updated_at?->toIso8601String(),
'editor' => $snippet->editor?->name,
])->all()];
}
private function registerBlocks(Blocks $blocks): void
{
// Baustein: gemeinsamer Inhalt, der auf vielen Seiten gleich erscheint
$blocks->add(BlockType::make(Snippets::BLOCK_TYPE, 'Baustein', 'component', 'layout', 'pages::Snippet')
->description('Wiederverwendbarer Inhalt – Änderungen am Baustein wirken auf allen Seiten.')
->fields([
Field::select('snippet', 'Baustein', fn () => ContentSnippet::query()->where('kind', ContentSnippet::BLOCK)->orderBy('name')->pluck('name', 'id')->all())
->help('Bausteine legen Sie unter Redaktion → Bausteine & Vorlagen an – oder direkt aus einem Block („Als Baustein speichern“).'),
])
->resolveUsing(fn (array $data, ?User $user, array $context) => $this->app->make(Snippets::class)->resolve($data, $user, $context)));
$blocks->add(BlockType::make('downloads', 'Downloads', 'file-down', 'media', 'pages::Downloads')
->description('Dateien zum Herunterladen – nur für Personen, die die Seite sehen dürfen.')
->fields([