[BUGFIX] Web->Function: empty frame if all related ext removed 30/35730/8
authorMathias Schreiber <mathias.schreiber@wmdb.de>
Fri, 2 Jan 2015 13:59:29 +0000 (14:59 +0100)
committerBenjamin Mack <benni@typo3.org>
Fri, 2 Jan 2015 15:48:23 +0000 (16:48 +0100)
Shows a meaningful error message if a module relies on submodules that
have not been registered yet.

Resolves: #21975
Releases: master, 6.2
Change-Id: Ibaf0ccae2a4d8f2aae066323d58dbacf321d107a
Reviewed-on: http://review.typo3.org/35730
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
Reviewed-by: Benjamin Mack <benni@typo3.org>
Tested-by: Benjamin Mack <benni@typo3.org>
typo3/sysext/backend/Classes/Module/BaseScriptClass.php
typo3/sysext/backend/Resources/Private/Language/locallang_errors.xlf [new file with mode: 0644]

index b9f1e63..ae8b554 100644 (file)
@@ -15,7 +15,10 @@ namespace TYPO3\CMS\Backend\Module;
  */
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
+use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Lang\LanguageService;
 
 /**
  * Parent class for 'ScriptClasses' in backend modules.
@@ -36,8 +39,8 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
  *
  * class PrototypeController extends \TYPO3\CMS\Backend\Module\BaseScriptClass {
  *     public function __construct() {
- *             $GLOBALS['LANG']->includeLLFile('EXT:prototype/Resources/Private/Language/locallang.xlf');
- *             $GLOBALS['BE_USER']->modAccess($GLOBALS['MCONF'], TRUE);
+ *             $this->getLanguageService()->includeLLFile('EXT:prototype/Resources/Private/Language/locallang.xlf');
+ *             $this->getBackendUser()->modAccess($GLOBALS['MCONF'], TRUE);
  *     }
  * }
  *
@@ -198,7 +201,7 @@ class BaseScriptClass {
                }
                $this->id = (int)GeneralUtility::_GP('id');
                $this->CMD = GeneralUtility::_GP('CMD');
-               $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
+               $this->perms_clause = $this->getBackendUser()->getPagePermsClause(1);
                $this->menuConfig();
                $this->handleExternalFunctionValue();
        }
@@ -233,8 +236,8 @@ class BaseScriptClass {
                $mergeArray = $GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey];
                if (is_array($mergeArray)) {
                        foreach ($mergeArray as $k => $v) {
-                               if (((string)$v['ws'] === '' || $GLOBALS['BE_USER']->workspace === 0 && GeneralUtility::inList($v['ws'], 'online')) || $GLOBALS['BE_USER']->workspace === -1 && GeneralUtility::inList($v['ws'], 'offline') || $GLOBALS['BE_USER']->workspace > 0 && GeneralUtility::inList($v['ws'], 'custom')) {
-                                       $menuArr[$k] = $GLOBALS['LANG']->sL($v['title']);
+                               if (((string)$v['ws'] === '' || $this->getBackendUser()->workspace === 0 && GeneralUtility::inList($v['ws'], 'online')) || $this->getBackendUser()->workspace === -1 && GeneralUtility::inList($v['ws'], 'offline') || $this->getBackendUser()->workspace > 0 && GeneralUtility::inList($v['ws'], 'custom')) {
+                                       $menuArr[$k] = $this->getLanguageService()->sL($v['title']);
                                }
                        }
                }
@@ -267,7 +270,10 @@ class BaseScriptClass {
         * @see handleExternalFunctionValue()
         */
        public function getExternalItemConfig($modName, $menuKey, $value = '') {
-               return (string)$value !== '' ? $GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey][$value] : $GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey];
+               if (isset($GLOBALS['TBE_MODULES_EXT'][$modName])) {
+                       return (string)$value !== '' ? $GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey][$value] : $GLOBALS['TBE_MODULES_EXT'][$modName]['MOD_MENU'][$menuKey];
+               }
+               return NULL;
        }
 
        /**
@@ -319,10 +325,36 @@ class BaseScriptClass {
         * @return void
         */
        public function extObjContent() {
-               $this->extObj->pObj = $this;
-               if (is_callable(array($this->extObj, 'main'))) {
-                       $this->content .= $this->extObj->main();
+               if ($this->extObj === NULL) {
+                       $flashMessage = GeneralUtility::makeInstance(
+                               FlashMessage::class,
+                               $this->getLanguageService()->sL('LLL:EXT:backend/Resources/Private/Language/locallang_errors.xlf:no_modules_registered'),
+                               $this->getLanguageService()->getLL('title'),
+                               FlashMessage::ERROR
+                       );
+                       $this->content .= $flashMessage->render();
+               } else {
+                       $this->extObj->pObj = $this;
+                       if (is_callable(array($this->extObj, 'main'))) {
+                               $this->content .= $this->extObj->main();
+                       }
                }
        }
 
+       /**
+        * Returns the Language Service
+        * @return LanguageService
+        */
+       protected function getLanguageService() {
+               return $GLOBALS['LANG'];
+       }
+
+       /**
+        * Returns the Backend User
+        * @return BackendUserAuthentication
+        */
+       protected function getBackendUser() {
+               return $GLOBALS['BE_USER'];
+       }
+
 }
diff --git a/typo3/sysext/backend/Resources/Private/Language/locallang_errors.xlf b/typo3/sysext/backend/Resources/Private/Language/locallang_errors.xlf
new file mode 100644 (file)
index 0000000..af75769
--- /dev/null
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xliff version="1.0" xmlns:t3="http://typo3.org/schemas/xliff">
+       <file t3:id="1420197366" source-language="en" datatype="plaintext" original="messages" date="2015-01-02T11:16:11Z" product-name="backend">
+               <header/>
+               <body>
+                       <trans-unit id="no_modules_registered" xml:space="preserve">
+                               <source>No modules have been registered. Please contact your system administrator.</source>
+                       </trans-unit>
+               </body>
+       </file>
+</xliff>