Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m56s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m2s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m9s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 2m40s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 2m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m29s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 55s
- Seiten-Plugin: Seitenbaum mit Adressen, Seitennavigation, Brotkrumen und optional Hauptnavigation; Sichtbarkeit vererbt sich auf Unterseiten - Pagebuilder (Block-Registry im Kern, Plugins tragen Blöcke bei): Abschnitt, Spalten, Tabs, Akkordeon, Box, Überschrift, Text (TipTap), Zitat, Schaltflächen, Symbolliste, Tabelle, Trennlinie, Abstand, Bild, Galerie, Video (erst nach Klick), Titelbild, Ansprechpartner, Downloads, Unterseiten, Neuigkeiten, Termine; Sichtbarkeit je Block; Bereinigung beim Speichern - Editor im Portal: Ziehen und Ablegen, Autospeichern als Entwurf, Rückgängig, Gerätevorschau, Versionen, Zeitsteuerung, Bearbeitungssperre, Freigabe anfordern - Rechte „inkl. Unterseiten“ werden im Rechte-Cache aufgelöst - Neuigkeiten: Schreiben im Portal, Freigabe-Workflow mit Benachrichtigungen - Bereich „Redaktion“, Benachrichtigungen im Portal - storage/.migrations-fingerprint nicht mehr ausliefern Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
102 lines
4.4 KiB
PHP
102 lines
4.4 KiB
PHP
<?php
|
||
|
||
namespace Inhaus\Plugins\Pages;
|
||
|
||
use App\Editorial\Editorial;
|
||
use App\Models\User;
|
||
use App\Pagebuilder\Blocks;
|
||
use App\Pagebuilder\BlockType;
|
||
use App\Pagebuilder\Field;
|
||
use App\Plugins\Plugin;
|
||
use App\Support\Abilities;
|
||
use App\Support\Navigation;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\Support\Facades\Gate;
|
||
use Illuminate\Support\Facades\Schedule;
|
||
use Inhaus\Plugins\Pages\Models\Page;
|
||
use Inhaus\Plugins\Pages\Models\PageFile;
|
||
use Inhaus\Plugins\Pages\Policies\PagePolicy;
|
||
|
||
class PagesPlugin extends Plugin
|
||
{
|
||
public function register(): void
|
||
{
|
||
$this->app->singleton(PageTree::class);
|
||
|
||
$abilities = $this->app->make(Abilities::class);
|
||
$abilities->define('pages.manage', 'Seiten: alle Seiten verwalten', 'Seiten');
|
||
$abilities->define('pages.edit', 'Seiten bearbeiten', 'Seiten', resource: 'page');
|
||
$abilities->define('pages.publish', 'Seiten veröffentlichen', 'Seiten', resource: 'page');
|
||
$abilities->resourceType(
|
||
'page',
|
||
'Seite',
|
||
fn () => $this->app->make(PageTree::class)->options(),
|
||
fn (array $ids) => $this->app->make(PageTree::class)->descendantIds($ids),
|
||
);
|
||
|
||
Gate::policy(Page::class, PagePolicy::class);
|
||
|
||
// Seiten der obersten Ebene mit „In der Hauptnavigation“ erscheinen dort.
|
||
$this->app->make(Navigation::class)->provider('pages', function (Request $request, ?User $user) {
|
||
$current = trim((string) $request->route('path'), '/');
|
||
|
||
return array_map(fn (array $page) => [
|
||
'key' => 'page-'.$page['id'],
|
||
'label' => $page['title'],
|
||
'href' => '/seiten/'.$page['path'],
|
||
'active' => $request->routeIs('pages.show') && ($current === $page['path'] || str_starts_with($current, $page['path'].'/')),
|
||
'sort' => 40 + $page['sort'],
|
||
], $this->app->make(PageTree::class)->navigation($user));
|
||
});
|
||
|
||
$this->app->make(Editorial::class)->add(
|
||
'pages',
|
||
'Seiten',
|
||
'pages::EditorialPages',
|
||
20,
|
||
fn (User $user) => app(PagePolicy::class)->viewAny($user),
|
||
fn (User $user) => EditorialPages::props($user),
|
||
);
|
||
|
||
$this->registerBlocks($this->app->make(Blocks::class));
|
||
}
|
||
|
||
public function boot(): void
|
||
{
|
||
// Zeitgesteuerte Veröffentlichungen. Beim Aufruf einer Seite wird ein fälliger Stand zusätzlich sofort übernommen.
|
||
Schedule::call(function () {
|
||
Page::query()->whereNotNull('scheduled_at')->where('scheduled_at', '<=', now())->get()->each->publishIfDue();
|
||
})->everyMinute()->name('pages-scheduled')->withoutOverlapping(5);
|
||
}
|
||
|
||
private function registerBlocks(Blocks $blocks): void
|
||
{
|
||
$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([
|
||
Field::text('title', 'Überschrift', 150),
|
||
Field::ids('files', 'Dateien', 'page-file'),
|
||
])
|
||
->resolveUsing(function (array $data, ?User $user, array $context) {
|
||
$files = PageFile::query()->whereIn('id', $data['files'])
|
||
->when(isset($context['page_id']), fn ($q) => $q->where('page_id', $context['page_id']))
|
||
->get()->keyBy('id');
|
||
|
||
return ['files' => collect($data['files'])->map(fn ($id) => $files->get($id)?->toBlockArray())->filter()->values()->all()];
|
||
}));
|
||
|
||
$blocks->add(BlockType::make('subpages', 'Unterseiten', 'folder-tree', 'dynamic', 'pages::Subpages')
|
||
->description('Verweise auf die Unterseiten dieser Seite.')
|
||
->fields([
|
||
Field::text('title', 'Überschrift', 150),
|
||
Field::select('layout', 'Darstellung', ['cards' => 'Kacheln', 'list' => 'Liste'], 'cards'),
|
||
])
|
||
->resolveUsing(function (array $data, ?User $user, array $context) {
|
||
$tree = $this->app->make(PageTree::class);
|
||
|
||
return ['pages' => isset($context['page_id'])
|
||
? array_map(fn (array $page) => ['id' => $page['id'], 'title' => $page['title'], 'url' => $page['url']], $tree->visibleTree($context['page_id'], $user, 1))
|
||
: []];
|
||
}));
|
||
}
|
||
}
|