Using page settings to build page location
authorAlexander Ebert <ebert@woltlab.com>
Sat, 9 Jul 2016 20:34:23 +0000 (22:34 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sat, 9 Jul 2016 20:34:23 +0000 (22:34 +0200)
wcfsetup/install/files/lib/system/breadcrumb/Breadcrumbs.class.php

index aa889263626e7f7671468fed8705a9ed09f55789..6169e515a1127a3e41f1b1cce21e382d2575645d 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\breadcrumb;
+use wcf\data\page\Page;
 use wcf\data\page\PageCache;
 use wcf\system\page\PageLocationManager;
 use wcf\system\SingletonFactory;
@@ -76,6 +77,9 @@ class Breadcrumbs extends SingletonFactory implements \Countable, \Iterator {
                throw new \BadMethodCallException("Breadcrumbs::remove() is no longer supported, please use " . PageLocationManager::class . " instead.");
        }
        
+       /**
+        * Loads the list of breadcrumbs.
+        */
        protected function loadBreadcrumbs() {
                $this->items = [];
                $locations = PageLocationManager::getInstance()->getLocations();
@@ -84,6 +88,28 @@ class Breadcrumbs extends SingletonFactory implements \Countable, \Iterator {
                // by all relevant ancestors, but breadcrumbs appear in the reverse order
                $locations = array_reverse($locations);
                
+               // use the top-most location to find the path up to the very top of
+               // the page order
+               if (!empty($locations)) {
+                       $location = $locations[0];
+                       
+                       if ($location['pageID']) {
+                               $page = PageCache::getInstance()->getPage($location['pageID']);
+                               while ($page->parentPageID) {
+                                       $page = PageCache::getInstance()->getPage($page->parentPageID);
+                                       
+                                       array_unshift($locations, [
+                                               'identifier' => $page->identifier,
+                                               'link' => $page->getLink(),
+                                               'pageID' => $page->pageID,
+                                               'pageObjectID' => 0,
+                                               'title' => $page->getTitle(),
+                                               'useAsParentLocation' => false
+                                       ]);
+                               }
+                       }
+               }
+               
                // add the landing page as first location, unless it is already included
                $landingPage = PageCache::getInstance()->getLandingPage();
                $addLandingPage = true;