settings->load()['notFoundPageId']; return '' === $id ? null : ($this->pages->choices(id: $id)[0] ?? null); } public function page(int $status = 404): array { $id = $this->settings->load()['notFoundPageId']; $published = 404 === $status && '' !== $id ? $this->pages->findPublishedById($id) : null; return [ 'id' => 'error-'.$status, 'path' => '', 'document' => self::document($status), ...($published ?? []), 'locale' => 'de', 'type' => 'page', 'robots' => 'noindex', 'seo_title' => '', 'header_area' => null, 'footer_area' => null, ]; } public static function document(int $status = 404): array { $title = 410 === $status ? 'Diese Seite ist nicht mehr verfügbar.' : 'Seite nicht gefunden'; return [ 'schemaVersion' => 10, 'title' => $title, 'description' => 'Die gesuchte Seite ist nicht verfügbar. Über die Startseite findest du wieder zum richtigen Inhalt.', 'blocks' => [[ 'id' => 'error-section', 'type' => 'section', 'style' => ['desktop' => ['textAlign' => 'center', 'minHeight' => '45vh', 'padding' => ['top' => '80px', 'bottom' => '80px']]], 'children' => [ ['id' => 'error-code', 'type' => 'text', 'props' => ['text' => (string) $status]], ['id' => 'error-heading', 'type' => 'heading', 'props' => ['text' => $title, 'level' => 1]], ['id' => 'error-message', 'type' => 'text', 'props' => ['text' => 'Die Adresse ist möglicherweise veraltet oder wurde falsch eingegeben. Über die Startseite findest du wieder zum richtigen Inhalt.']], ['id' => 'error-home', 'type' => 'button', 'props' => ['text' => 'Zur Startseite', 'href' => '/']], ], ]], ]; } public function create(string $expectedId): string { return $this->db->transactional(function () use ($expectedId): string { if (null !== $this->selected()) { throw new InvalidPage('Es ist bereits eine 404-Seite zugewiesen. Du kannst sie direkt bearbeiten.'); } $slug = '404'; for ($suffix = 2; false !== $this->db->fetchOne('SELECT id FROM page WHERE website_id = ? AND locale = ? AND path = ?', ['default', 'de', $slug]); ++$suffix) { $slug = '404-'.$suffix; } $id = $this->pages->createPage($slug, null, 'page', self::document()); $this->db->executeStatement('UPDATE page SET robots = ? WHERE id = ?', ['noindex', $id]); $this->settings->assignNotFoundPage($id, $expectedId); return $id; }); } }