Pārlūkot izejas kodu

refactor the page error system

Olivier Massot 5 gadi atpakaļ
vecāks
revīzija
54902fb266

+ 36 - 4
ot_templating/Classes/Page/ErrorHandler.php

@@ -4,7 +4,7 @@ namespace Opentalent\OtTemplating\Page;
 
 
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
 use Psr\Http\Message\ServerRequestInterface;
-use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
+use TYPO3\CMS\Core\Error\PageErrorHandler\PageContentErrorHandler;
 use TYPO3\CMS\Core\Error\PageErrorHandler\PageErrorHandlerInterface;
 use TYPO3\CMS\Core\Error\PageErrorHandler\PageErrorHandlerInterface;
 use TYPO3\CMS\Core\Http\HtmlResponse;
 use TYPO3\CMS\Core\Http\HtmlResponse;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
@@ -66,18 +66,50 @@ class ErrorHandler implements PageErrorHandlerInterface
         array $reasons = []
         array $reasons = []
     ): ResponseInterface {
     ): ResponseInterface {
 
 
+        $homeUri = "https://opentalent.fr";
+        $title = 'Page introuvable';
+
+        // This variable role is to prevent redirection loop,
+        $isCircular = preg_match('/.*\/page-introuvable/', $request->getUri()->getPath());
+
         $pageRepository = GeneralUtility::makeInstance(OtPageRepository::class);
         $pageRepository = GeneralUtility::makeInstance(OtPageRepository::class);
         $site = $pageRepository->getCurrentSite();
         $site = $pageRepository->getCurrentSite();
-        $baseUri = $site->getBase();
 
 
+        if ($site && !$isCircular){
+            $homeUri = $site->getBase();
+            $rootUid = $site->getRootPageId();
+
+            $rootPage = $pageRepository->getPage($rootUid);
+            $title = $rootPage['title'];
+
+            $subPages = $pageRepository->getAllSubpagesForPage($rootUid, true);
+            foreach ($subPages as $page) {
+                if ($page['slug'] == '/page-introuvable') {
+
+                    $errorHandler = GeneralUtility::makeInstance(
+                        PageContentErrorHandler::class,
+                        $this->statusCode,
+                        [
+                            'errorHandler' => 'Page',
+                            'errorContentSource' => 't3://page?uid=' . $page['uid']
+                        ]
+                    );
+                    return $errorHandler->handlePageError($request, $message, $reasons);
+                }
+            }
+        }
+
+        // At this point, the site has not been determined or
+        //   this site has no subpage with slug '/page-introuvable'
         $this->view->assignMultiple([
         $this->view->assignMultiple([
             'request' => $request,
             'request' => $request,
             'message' => $message,
             'message' => $message,
             'reasons' => $reasons,
             'reasons' => $reasons,
-            'homeUri' => $baseUri,
-            'siteTitle' => $site->getConfiguration()['websiteTitle']
+            'homeUri' => $homeUri,
+            'siteTitle' => $title
         ]);
         ]);
 
 
         return new HtmlResponse($this->view->render(), $this->statusCode);
         return new HtmlResponse($this->view->render(), $this->statusCode);
     }
     }
+
 }
 }

+ 6 - 5
ot_templating/Classes/Page/OtPageRepository.php

@@ -62,20 +62,21 @@ class OtPageRepository extends PageRepository
     }
     }
 
 
 
 
-
-
     /**
     /**
      * Recursively returns all the subpages of the given page
      * Recursively returns all the subpages of the given page
      *
      *
-     * @param $pageUid
+     * @param int $pageUid The uid of the parent page
+     * @param bool $withRestrictions Set to true to add the standard restrictions (deleted, forbidden...etc.)
      * @return array
      * @return array
      */
      */
-    public function getAllSubpagesForPage($pageUid) {
+    public function getAllSubpagesForPage($pageUid, bool $withRestrictions=false) {
         $subpages = [];
         $subpages = [];
 
 
         $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
         $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
             ->getQueryBuilderForTable('pages');
             ->getQueryBuilderForTable('pages');
-        $queryBuilder->getRestrictions()->removeAll();
+        if (!$withRestrictions) {
+            $queryBuilder->getRestrictions()->removeAll();
+        }
         $stack = $queryBuilder
         $stack = $queryBuilder
             ->select('*')
             ->select('*')
             ->from('pages')
             ->from('pages')

+ 0 - 25
ot_templating/Resources/Private/Layouts/Classic/E404.html

@@ -1,25 +0,0 @@
-{namespace v=FluidTYPO3\Vhs\ViewHelpers}
-{namespace ot=Opentalent\OtTemplating\ViewHelpers}
-
-<f:comment><!-- Special layout for the All Events page --></f:comment>
-<f:layout name="E404" />
-
-<f:comment><!-- Render the header defined in partials/Header.html--></f:comment>
-<f:render partial="Classic/Header" arguments="{_all}" />
-
-<div class="main">
-
-    <f:comment><!-- Central column --></f:comment>
-    <div class="content">
-
-        <div class="errpage">
-            <h3>Erreur 404 - Page introuvable</h3>
-
-            <p>Il semblerait que la page que vous souhaitez consulter n'existe pas ou n'est plus disponible</p>
-            <p>Veuillez vérifier que l'URL saisie est bien correcte</p>
-        </div>
-    </div>
-</div>
-
-<f:comment><!-- Render the footer defined in partials/footer.html--></f:comment>
-<f:render partial="Classic/Footer" />

+ 68 - 0
ot_templating/Resources/Private/Layouts/ErrorPage.html

@@ -0,0 +1,68 @@
+<f:comment><!-- A common error layout for 403, 404, 500 errors... --></f:comment>
+
+<!DOCTYPE html>
+<html dir="ltr" lang="fr-FR">
+<head>
+    <meta charset="utf-8">
+
+    <title>{siteTitle}</title>
+    <meta name="generator" content="TYPO3 CMS" />
+    <meta name="robots" content="index,follow,archive" />
+    <meta name="viewport" content="width=device-width" />
+    <meta name="twitter:card" content="summary" />
+
+    <style>
+        #errpage {
+            width: 100%;
+            font-family: 'Source Sans Pro',sans-serif;;
+        }
+
+        #errpage header {
+            display: flex;
+            flex-direction: row;
+            justify-content: center;
+            align-items: center;
+            height: 200px;
+        }
+
+        #errpage .title {
+            color: #4d4d4d;
+        }
+
+        #errpage .message {
+            display: flex;
+            flex-direction: column;
+            justify-content: center;
+            align-items: center;
+            text-align: center;
+            min-height: 200px;
+            line-height: 2em;
+            font-size: 17px;
+            padding: 24px 0;
+            background-color: #ffe6cc;
+        }
+
+        #errpage a {
+            margin-top: 16px;
+            font-weight: bold;
+            color: #b35c00;
+            text-decoration: none;
+            padding: 3px;
+        }
+
+        #errpage a:hover {
+            color: #994f00;
+        }
+    </style>
+</head>
+<body>
+    <div id="errpage">
+        <header>
+            <h1 class="title">{siteTitle}</h1>
+        </header>
+
+        <div class="message">
+            <f:render section="Message" />
+        </div>
+    </div>
+</body>

+ 0 - 33
ot_templating/Resources/Private/Layouts/Modern/E404.html

@@ -1,33 +0,0 @@
-{namespace v=FluidTYPO3\Vhs\ViewHelpers}
-{namespace ot=Opentalent\OtTemplating\ViewHelpers}
-
-<f:comment><!-- Special layout for the All Events page --></f:comment>
-<f:layout name="E404" />
-
-<section class="t-container st-effect-3">
-    <div class="wrapper">
-
-        <f:comment><!-- Render the header defined in partials/Header.html--></f:comment>
-        <f:render partial="Modern/Header" arguments="{_all}" />
-
-        <section class="page-section-ptb">
-            <div class="container">
-                <div class="row">
-                    <div class="col-sm-12 mt-30">
-
-                        <div class="errpage">
-                            <h2>Erreur 404 - Page introuvable</h2>
-
-                            <p>Il semblerait que la page que vous souhaitez consulter n'existe pas ou n'est plus disponible</p>
-                            <p>Veuillez vérifier que l'URL saisie est bien correcte</p>
-                        </div>
-
-                    </div>
-                </div>
-            </div>
-        </section>
-
-        <f:comment><!-- Render the footer defined in partials/footer.html--></f:comment>
-        <f:render partial="Modern/Footer" />
-    </div>
-</section>

+ 0 - 17
ot_templating/Resources/Private/Templates/Page/E404.html

@@ -1,17 +0,0 @@
-{namespace flux=FluidTYPO3\Flux\ViewHelpers}
-{namespace ot=Opentalent\OtTemplating\ViewHelpers}
-
-<f:comment><!-- uses the layout 1Col, defined in layouts/[templateName]/1Col.html --></f:comment>
-<f:layout name="{ot:template.current()}/E404" />
-
-<f:section name='Configuration'>
-    <flux:form id="e404" label="Gabarit Page introuvable" extensionName="Opentalent.OtTemplating">
-    </flux:form>
-
-    <f:comment><!-- Backend layout grid --></f:comment>
-    <flux:grid>
-        <flux:grid.row>
-        </flux:grid.row>
-    </flux:grid>
-</f:section>
-

+ 7 - 0
ot_templating/Resources/Private/Templates/Page/Error/403.html

@@ -0,0 +1,7 @@
+<f:layout name="ErrorPage" />
+
+<f:section name="Message">
+    <p>Vous n'êtes pas autorisé à consulter cette page</p>
+    <p>Avez vous pensé à vous authentifier?</p>
+    <a href="{homeUri}">Revenir à la page d'accueil</a>
+</f:section>

+ 11 - 0
ot_templating/Resources/Private/Templates/Page/Error/404.html

@@ -0,0 +1,11 @@
+{namespace flux=FluidTYPO3\Flux\ViewHelpers}
+
+<f:layout name="ErrorPage" />
+
+<f:section name="Message">
+    <p>Il semblerait que la page que vous souhaitez consulter n'existe pas ou n'est plus disponible.</p>
+    <p>
+        Veuillez vérifier que l'URL saisie est bien correcte, ou
+        <a href="{homeUri}">cliquez ici pour revenir à la page d'accueil.</a>
+    </p>
+</f:section>

+ 5 - 0
ot_templating/Resources/Private/Templates/Page/Error/500.html

@@ -0,0 +1,5 @@
+<f:layout name="ErrorPage" />
+
+<f:section name="Message">
+    <p>Une erreur s'est produite, nous nous excusons pour la gêne occasionnée</p>
+</f:section>