Add event for resolving the active page
authorMarcel Werk <burntime@woltlab.com>
Sun, 10 Sep 2023 13:55:07 +0000 (15:55 +0200)
committerMarcel Werk <burntime@woltlab.com>
Sun, 10 Sep 2023 13:55:07 +0000 (15:55 +0200)
This event allows to add custom logic for resolving the active page.

wcfsetup/install/files/lib/system/page/PageLocationManager.class.php
wcfsetup/install/files/lib/system/page/event/ResolveCurrentPage.class.php [new file with mode: 0644]

index b580bcb4c0ff4d151a1b43cdaa9a88aaf7d0ff7f..f3b1914540ca2b5c48928638b2951f53cc6c5de6 100644 (file)
@@ -4,7 +4,9 @@ namespace wcf\system\page;
 
 use wcf\data\ITitledLinkObject;
 use wcf\data\page\PageCache;
+use wcf\system\event\EventHandler;
 use wcf\system\exception\SystemException;
+use wcf\system\page\event\ResolveCurrentPage;
 use wcf\system\request\RequestHandler;
 use wcf\system\SingletonFactory;
 use wcf\system\WCF;
@@ -51,6 +53,13 @@ class PageLocationManager extends SingletonFactory
             $page = PageCache::getInstance()->getPage($pageID);
         } else {
             $page = PageCache::getInstance()->getPageByController($activeRequest->getClassName());
+
+            if ($page === null) {
+                $event = new ResolveCurrentPage($activeRequest);
+                EventHandler::getInstance()->fire($event);
+                $page = $event->page;
+            }
+
             if ($page !== null) {
                 $pageID = $page->pageID;
 
diff --git a/wcfsetup/install/files/lib/system/page/event/ResolveCurrentPage.class.php b/wcfsetup/install/files/lib/system/page/event/ResolveCurrentPage.class.php
new file mode 100644 (file)
index 0000000..25510e3
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+
+namespace wcf\system\page\event;
+
+use wcf\data\page\Page;
+use wcf\system\event\IEvent;
+use wcf\system\request\Request;
+
+/**
+ * Indicates that the `PageLocationManager` could not determine the active page.
+ *
+ * @author  Marcel Werk
+ * @copyright   2001-2023 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @since   6.0
+ */
+final class ResolveCurrentPage implements IEvent
+{
+    public Page|null $page = null;
+
+    public function __construct(public readonly Request $request)
+    {
+    }
+}