[TASK] Use ModuleTemplate API for EXT:documentation 92/43792/5
authorMathias Schreiber <mathias.schreiber@wmdb.de>
Sun, 4 Oct 2015 15:44:33 +0000 (17:44 +0200)
committerAlexander Opitz <opitz.alexander@googlemail.com>
Mon, 5 Oct 2015 14:43:00 +0000 (16:43 +0200)
Releases: master
Resolves: #70355
Change-Id: Iebd1ef1229f24fd8fd2ea82f33d57af1a21644a9
Reviewed-on: http://review.typo3.org/43792
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
Reviewed-by: Alexander Opitz <opitz.alexander@googlemail.com>
Tested-by: Alexander Opitz <opitz.alexander@googlemail.com>
typo3/sysext/documentation/Classes/Controller/DocumentController.php
typo3/sysext/documentation/Classes/ViewHelpers/Be/Security/IfAdminViewHelper.php [deleted file]
typo3/sysext/documentation/Resources/Private/Layouts/Default.html

index 3211797..71a5c50 100644 (file)
@@ -14,59 +14,122 @@ namespace TYPO3\CMS\Documentation\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Backend\View\BackendTemplateView;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Documentation\Domain\Repository\DocumentRepository;
+use TYPO3\CMS\Documentation\Service\DocumentationService;
+use TYPO3\CMS\Documentation\Utility\LanguageUtility;
+use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
+use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
+use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
+use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
+use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
+use TYPO3\CMS\Lang\LanguageService;
 
 /**
  * Main controller of the Documentation module.
  */
-class DocumentController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
+class DocumentController extends ActionController {
 
        /**
-        * @var \TYPO3\CMS\Documentation\Domain\Repository\DocumentRepository
+        * @var DocumentRepository
         */
        protected $documentRepository;
 
        /**
-        * @var \TYPO3\CMS\Documentation\Service\DocumentationService
+        * @var DocumentationService
         */
        protected $documentationService;
 
        /**
-        * @var \TYPO3\CMS\Documentation\Utility\LanguageUtility
+        * @var LanguageUtility
         */
        protected $languageUtility;
 
        /**
-        * @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
+        * @var Dispatcher
         */
        protected $signalSlotDispatcher;
 
        /**
-        * @param \TYPO3\CMS\Documentation\Domain\Repository\DocumentRepository $documentRepository
+        * Backend Template Container
+        *
+        * @var BackendTemplateView
+        */
+       protected $defaultViewObjectName = BackendTemplateView::class;
+
+       /**
+        * BackendTemplateContainer
+        *
+        * @var BackendTemplateView
+        */
+       protected $view;
+
+       /**
+        * Set up the doc header properly here
+        *
+        * @param ViewInterface $view
+        */
+       protected function initializeView(ViewInterface $view) {
+               /** @var BackendTemplateView $view */
+               parent::initializeView($view);
+               $view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation([]);
+               $uriBuilder = $this->objectManager->get(UriBuilder::class);
+               $uriBuilder->setRequest($this->request);
+
+               $this->view->getModuleTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Documentation/Main');
+               $menu = $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->makeMenu();
+               $menu->setIdentifier('DocumentationModuleMenu');
+
+               $isListActive = $this->request->getControllerActionName() === 'list' ? TRUE : FALSE;
+               $uri = $uriBuilder->reset()->uriFor('list', array(), 'Document');
+               $listMenuItem = $menu->makeMenuItem()
+                       ->setTitle($this->getLanguageService()->sL('LLL:EXT:documentation/Resources/Private/Language/locallang.xlf:showDocumentation'))
+                       ->setHref($uri)
+                       ->setActive($isListActive);
+               $menu->addMenuItem($listMenuItem);
+
+               if ($this->getBackendUser()->isAdmin()) {
+                       $isDownloadActive = $this->request->getControllerActionName() ===
+                       'download' ? TRUE : FALSE;
+                       $uri =
+                               $uriBuilder->reset()->uriFor('download', array(), 'Document');
+                       $downloadMenuItem = $menu->makeMenuItem()
+                               ->setTitle($this->getLanguageService()->sL('LLL:EXT:documentation/Resources/Private/Language/locallang.xlf:downloadDocumentation'))
+                               ->setHref($uri)
+                               ->setActive($isDownloadActive);
+                       $menu->addMenuItem($downloadMenuItem);
+               }
+
+               $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
+       }
+
+       /**
+        * @param DocumentRepository $documentRepository
         */
-       public function injectDocumentRepository(\TYPO3\CMS\Documentation\Domain\Repository\DocumentRepository $documentRepository) {
+       public function injectDocumentRepository(DocumentRepository $documentRepository) {
                $this->documentRepository = $documentRepository;
        }
 
        /**
-        * @param \TYPO3\CMS\Documentation\Service\DocumentationService $documentationService
+        * @param DocumentationService $documentationService
         */
-       public function injectDocumentationService(\TYPO3\CMS\Documentation\Service\DocumentationService $documentationService) {
+       public function injectDocumentationService(DocumentationService $documentationService) {
                $this->documentationService = $documentationService;
        }
 
        /**
-        * @param \TYPO3\CMS\Documentation\Utility\LanguageUtility $languageUtility
+        * @param LanguageUtility $languageUtility
         */
-       public function injectLanguageUtility(\TYPO3\CMS\Documentation\Utility\LanguageUtility $languageUtility) {
+       public function injectLanguageUtility(LanguageUtility $languageUtility) {
                $this->languageUtility = $languageUtility;
        }
 
        /**
-        * @param \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher
+        * @param Dispatcher $signalSlotDispatcher
         */
-       public function injectSignalSlotDispatcher(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher) {
+       public function injectSignalSlotDispatcher(Dispatcher $signalSlotDispatcher) {
                $this->signalSlotDispatcher = $signalSlotDispatcher;
        }
 
@@ -76,6 +139,8 @@ class DocumentController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
         * @return void
         */
        public function listAction() {
+               $this->view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation([]);
+
                $documents = $this->getDocuments();
 
                // Filter documents to be shown for current user
@@ -167,7 +232,7 @@ class DocumentController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
                        $result = $this->documentationService->fetchNearestDocument($url, $key, $version ?: 'latest', $language);
                        if ($result) {
                                $this->addFlashMessage(
-                                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                       LocalizationUtility::translate(
                                                'downloadSucceeded',
                                                'documentation'
                                        ),
@@ -176,11 +241,11 @@ class DocumentController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
                                );
                        } else {
                                $this->addFlashMessage(
-                                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                       LocalizationUtility::translate(
                                                'downloadFailedNoArchive',
                                                'documentation'
                                        ),
-                                       \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                                       LocalizationUtility::translate(
                                                'downloadFailed',
                                                'documentation'
                                        ),
@@ -189,7 +254,7 @@ class DocumentController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
                        }
                } catch (\Exception $e) {
                        $this->addFlashMessage(
-                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                               LocalizationUtility::translate(
                                        'downloadFailedDetails',
                                        'documentation',
                                        array(
@@ -198,7 +263,7 @@ class DocumentController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
                                                $e->getCode()
                                        )
                                ),
-                               \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate(
+                               LocalizationUtility::translate(
                                        'downloadFailed',
                                        'documentation'
                                ),
@@ -217,4 +282,13 @@ class DocumentController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
                return $GLOBALS['BE_USER'];
        }
 
+       /**
+        * Returns the LanguageService
+        *
+        * @return LanguageService
+        */
+       protected function getLanguageService() {
+               return $GLOBALS['LANG'];
+       }
+
 }
diff --git a/typo3/sysext/documentation/Classes/ViewHelpers/Be/Security/IfAdminViewHelper.php b/typo3/sysext/documentation/Classes/ViewHelpers/Be/Security/IfAdminViewHelper.php
deleted file mode 100644 (file)
index 2bc551b..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-<?php
-namespace TYPO3\CMS\Documentation\ViewHelpers\Be\Security;
-
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-
-/**
- * This view helper checks whether a given BE user is admin or not.
- *
- * = Examples =
- *
- * <code title="Basic usage">
- * <doc:be.security.ifAdmin>
- * You see this is you're an admin.
- * </doc:be.security.ifAdmin>
- * </code>
- * <output>
- * You see this is you're an admin. (if an admin user, of course)
- * </output>
- *
- * <code title="Usage with then / else">
- * <doc:be.security.ifAdmin>
- * <f:then>
- * You see this is you're an admin.
- * </f:then>
- * <f:else>
- * You see this is you're not an admin.
- * </f:else>
- * </doc:be.security.ifAdmin>
- * </code>
- * <output>
- * Content of the "then" tag if an admin, content of the "else" tag otherwise.
- * </output>
- *
- * @api
- * @internal
- */
-class IfAdminViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper {
-
-       /**
-        * This method decides if the condition is TRUE or FALSE. It can be overriden in extending viewhelpers to adjust functionality.
-        *
-        * @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper, allows for flexiblity in overriding this method.
-        * @return bool
-        */
-       static protected function evaluateCondition($arguments = NULL) {
-               return $GLOBALS['BE_USER']->isAdmin();
-       }
-}
index 74ac34e..7fdff46 100644 (file)
@@ -1,26 +1,5 @@
-{namespace doc=TYPO3\CMS\Documentation\ViewHelpers}
-
-<f:be.container pageTitle="{f:translate(key: 'documentation_manager')}" enableClickMenu="false" loadJQuery="true"
-       includeRequireJsModules="{
-               0: 'TYPO3/CMS/Documentation/Main'
-       }">
-
-       <div id="typo3-docheader">
-               <div class="typo3-docheader-functions">
-                       <f:be.menus.actionMenu>
-                               <f:be.menus.actionMenuItem label="{f:translate(key: 'showDocumentation')}" controller="Document" action="list" />
-                               <doc:be.security.ifAdmin>
-                                       <f:be.menus.actionMenuItem label="{f:translate(key: 'downloadDocumentation')}" controller="Document" action="download" />
-                               </doc:be.security.ifAdmin>
-                       </f:be.menus.actionMenu>
-               </div>
-               <div class="typo3-docheader-buttons"></div>
-       </div>
-       <div id="typo3-docbody">
-               <div id="typo3-inner-docbody" class="typo3-documentation">
-                       <f:render section="module-headline" />
-                       <f:flashMessages />
-                       <f:render section="Content" />
-               </div>
-       </div>
-</f:be.container>
+<div class="typo3-documentation">
+       <f:render section="module-headline" />
+       <f:flashMessages />
+       <f:render section="Content" />
+</div>