From 0eaac6b92f912f8c0f15369eebfb5bca955b4980 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Wed, 26 Dec 2012 04:28:16 +0100 Subject: [PATCH] Added AbstractApplication::isActiveApplication() If you're developing an own application, simply add a protected variable "$abbreviation" and assign the application's abbreviation (e.g. "wbb"). Furthermore the package id is automatically set and can be accessed through $this->packageID. In case you're setting the active page menu item and adding a "top" breadcrumb for your application, please do so if $this->isActiveApplication() returns true. If you fail to check this, multiple applications will stack their breadcrumbs and the active page menu item would no longer be deterministic. --- .../application/AbstractApplication.class.php | 44 ++++++++++++++++++- .../system/application/IApplication.class.php | 7 +++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/wcfsetup/install/files/lib/system/application/AbstractApplication.class.php b/wcfsetup/install/files/lib/system/application/AbstractApplication.class.php index b6fd0acf07..da3865b50f 100644 --- a/wcfsetup/install/files/lib/system/application/AbstractApplication.class.php +++ b/wcfsetup/install/files/lib/system/application/AbstractApplication.class.php @@ -1,5 +1,6 @@ abbreviation) || $this->abbreviation == 'wcf') { + throw new SystemException("Unable to determine application, abbreviation is missing"); + } + + $application = ApplicationHandler::getInstance()->getApplication($this->abbreviation); + if ($application === null) { + throw new SystemException("Unable to determine application, abbreviation is unknown"); + } + + $this->packageID = $application->packageID; + + // check if current application is active (directly invoked, not dependent) + if ($application->packageID == ApplicationHandler::getInstance()->getActiveApplication()->packageID) { + $this->isActiveApplication = true; + } + } + + /** + * @see wcf\system\application\IApplication::isActiveApplication() + */ + public function isActiveApplication() { + return $this->isActiveApplication; + } /** * @see wcf\system\application\IApplication::__callStatic() diff --git a/wcfsetup/install/files/lib/system/application/IApplication.class.php b/wcfsetup/install/files/lib/system/application/IApplication.class.php index ed34e33475..d6c88b052d 100644 --- a/wcfsetup/install/files/lib/system/application/IApplication.class.php +++ b/wcfsetup/install/files/lib/system/application/IApplication.class.php @@ -17,6 +17,13 @@ interface IApplication { */ public function __run(); + /** + * Returns true, if current application is treated as active and was invoked directly. + * + * @return boolean + */ + public function isActiveApplication(); + /** * Forwards unknown method calls to WCF. * -- 2.20.1