[TASK] Use ModuleTemplate API for EXT:workspaces 15/43815/7
authorMathias Schreiber <mathias.schreiber@wmdb.de>
Mon, 5 Oct 2015 11:24:59 +0000 (13:24 +0200)
committerOliver Hader <oliver.hader@typo3.org>
Sat, 10 Oct 2015 08:15:44 +0000 (10:15 +0200)
* makes use of the new ModuleTemplate and DocHeaderComponent
* registers icon for preview link generation at IconRegistry
* resolves superfluous custom processRequest() logic
* disables DocHeaderComponent in frontend preview

Releases: master
Resolves: #69889
Change-Id: I9b677b3954d5129f36b64f9cba4ce6479744a75c
Reviewed-on: http://review.typo3.org/43815
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Frank N├Ągler <frank.naegler@typo3.org>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
typo3/sysext/workspaces/Classes/Controller/AbstractController.php
typo3/sysext/workspaces/Classes/Controller/PreviewController.php
typo3/sysext/workspaces/Classes/Controller/ReviewController.php
typo3/sysext/workspaces/Resources/Private/Layouts/Module.html
typo3/sysext/workspaces/ext_tables.php

index 5a93d43..16effd2 100644 (file)
@@ -18,6 +18,7 @@ use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Backend\View\BackendTemplateView;
 
 /**
  * Abstract action controller.
@@ -25,6 +26,16 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
 class AbstractController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
 {
     /**
+     * @var string
+     */
+    protected $defaultViewObjectName = BackendTemplateView::class;
+
+    /**
+     * @var BackendTemplateView
+     */
+    protected $view;
+
+    /**
      * @var string Key of the extension this controller belongs to
      */
     protected $extensionName = 'Workspaces';
@@ -46,6 +57,7 @@ class AbstractController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
      */
     protected function initializeAction()
     {
+        $this->pageRenderer = $this->getPageRenderer();
         // @todo Evaluate how the intval() call can be used with Extbase validators/filters
         $this->pageId = (int)GeneralUtility::_GP('id');
         $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
@@ -98,26 +110,6 @@ class AbstractController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionControl
     }
 
     /**
-     * Processes a general request. The result can be returned by altering the given response.
-     *
-     * @param \TYPO3\CMS\Extbase\Mvc\RequestInterface $request The request object
-     * @param \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response The response, modified by this handler
-     * @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException if the controller doesn't support the current request type
-     * @return void
-     */
-    public function processRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)
-    {
-        $this->template = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
-        $this->pageRenderer = $this->getPageRenderer();
-        $GLOBALS['SOBE'] = new \stdClass();
-        $GLOBALS['SOBE']->doc = $this->template;
-        parent::processRequest($request, $response);
-        $pageHeader = $this->template->startpage($GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:module.title'));
-        $pageEnd = $this->template->endPage();
-        $response->setContent($pageHeader . $response->getContent() . $pageEnd);
-    }
-
-    /**
      * Gets the selected language.
      *
      * @return string
index ada007f..ea51552 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Workspaces\Controller;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Backend\View\BackendTemplateView;
 
 /**
  * Implements the preview controller of the workspace module.
@@ -34,6 +35,17 @@ class PreviewController extends AbstractController
     protected $workspaceService;
 
     /**
+     * Set up the doc header properly here
+     *
+     * @param BackendTemplateView $view
+     */
+    protected function initializeView(BackendTemplateView $view)
+    {
+        parent::initializeView($view);
+        $view->getModuleTemplate()->getDocHeaderComponent()->disable();
+    }
+
+    /**
      * Initializes the controller before invoking an action method.
      *
      * @return void
@@ -43,7 +55,7 @@ class PreviewController extends AbstractController
         parent::initializeAction();
         $this->stageService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\StagesService::class);
         $this->workspaceService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class);
-        $this->template->setExtDirectStateProvider();
+        $this->pageRenderer->addJsFile('sysext/backend/Resources/Public/JavaScript/ExtDirect.StateProvider.js');
         $resourcePath = ExtensionManagementUtility::extRelPath('workspaces') . 'Resources/Public/Css/preview.css';
         $GLOBALS['TBE_STYLES']['extJS']['theme'] = $resourcePath;
         $this->pageRenderer->loadExtJS();
index 6c25a59..e70584d 100644 (file)
@@ -14,6 +14,9 @@ namespace TYPO3\CMS\Workspaces\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Backend\Template\Components\ButtonBar;
+use TYPO3\CMS\Backend\View\BackendTemplateView;
+use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Workspaces\Service\WorkspaceService;
@@ -24,6 +27,37 @@ use TYPO3\CMS\Workspaces\Service\WorkspaceService;
 class ReviewController extends AbstractController
 {
     /**
+     * Set up the doc header properly here
+     *
+     * @param BackendTemplateView $view
+     */
+    protected function initializeView(BackendTemplateView $view)
+    {
+        parent::initializeView($view);
+        $this->registerButtons();
+    }
+
+    /**
+     * Registers the DocHeader buttons
+     */
+    protected function registerButtons()
+    {
+        $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
+        $currentRequest = $this->request;
+        $moduleName = $currentRequest->getPluginName();
+        $getVars = $this->request->getArguments();
+        $extensionName = $currentRequest->getControllerExtensionName();
+        if (count($getVars) === 0) {
+            $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
+            $getVars = array('id', 'M', $modulePrefix);
+        }
+        $getList = implode(',', $getVars);
+        $shortcutButton = $buttonBar->makeFullyRenderedButton()
+            ->setHtmlSource($this->view->getModuleTemplate()->makeShortcutIcon($getList, '', $moduleName));
+        $buttonBar->addButton($shortcutButton, ButtonBar::BUTTON_POSITION_RIGHT, 2);
+    }
+
+    /**
      * Renders the review module user dependent with all workspaces.
      * The module will show all records of one workspace.
      *
@@ -31,12 +65,14 @@ class ReviewController extends AbstractController
      */
     public function indexAction()
     {
-        $wsService = GeneralUtility::makeInstance(\TYPO3\CMS\Workspaces\Service\WorkspaceService::class);
+        /** @var WorkspaceService $wsService */
+        $wsService = GeneralUtility::makeInstance(WorkspaceService::class);
         $this->view->assign('showGrid', !($GLOBALS['BE_USER']->workspace === 0 && !$GLOBALS['BE_USER']->isAdmin()));
         $this->view->assign('showAllWorkspaceTab', true);
         $this->view->assign('pageUid', GeneralUtility::_GP('id'));
         if (GeneralUtility::_GP('id')) {
             $pageRecord = BackendUtility::getRecord('pages', GeneralUtility::_GP('id'));
+            $this->view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation($pageRecord);
             $this->view->assign('pageTitle', BackendUtility::getRecordTitle('pages', $pageRecord));
         }
         $this->view->assign('showLegend', !($GLOBALS['BE_USER']->workspace === 0 && !$GLOBALS['BE_USER']->isAdmin()));
@@ -70,6 +106,16 @@ class ReviewController extends AbstractController
         $this->view->assign('workspaceList', $wsList);
         $this->view->assign('activeWorkspaceUid', $activeWorkspace);
         $this->view->assign('activeWorkspaceTitle', WorkspaceService::getWorkspaceTitle($activeWorkspace));
+        if ($wsService->canCreatePreviewLink(GeneralUtility::_GP('id'), $activeWorkspace)) {
+            $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
+            $iconFactory = $this->view->getModuleTemplate()->getIconFactory();
+            $showButton = $buttonBar->makeLinkButton()
+                ->setHref('#')
+                ->setOnClick('TYPO3.Workspaces.Actions.generateWorkspacePreviewLinksForAllLanguages();return false;')
+                ->setTitle($this->getLanguageService()->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:tooltip.generatePagePreview', true))
+                ->setIcon($iconFactory->getIcon('module-workspaces-action-preview-link', Icon::SIZE_SMALL));
+            $buttonBar->addButton($showButton);
+        }
         $this->view->assign('showPreviewLink', $wsService->canCreatePreviewLink(GeneralUtility::_GP('id'), $activeWorkspace));
         $GLOBALS['BE_USER']->setAndSaveSessionData('tx_workspace_activeWorkspace', $activeWorkspace);
     }
@@ -134,7 +180,7 @@ class ReviewController extends AbstractController
     protected function initializeAction()
     {
         parent::initializeAction();
-        $this->template->setExtDirectStateProvider();
+        $this->pageRenderer->addJsFile('sysext/backend/Resources/Public/JavaScript/ExtDirect.StateProvider.js');
         if (WorkspaceService::isOldStyleWorkspaceUsed()) {
             $flashMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class, $GLOBALS['LANG']->sL('LLL:EXT:workspaces/Resources/Private/Language/locallang.xlf:warning.oldStyleWorkspaceInUser'), '', \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING);
             /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
@@ -261,4 +307,12 @@ class ReviewController extends AbstractController
         }
         return BackendUtility::getModuleUrl('web_WorkspacesWorkspaces', $parameters);
     }
+
+    /**
+     * @return \TYPO3\CMS\Lang\LanguageService
+     */
+    protected function getLanguageService()
+    {
+        return $GLOBALS['LANG'];
+    }
 }
index de1b85e..9fe98a1 100644 (file)
@@ -1,34 +1,5 @@
-<!-- ###FULLDOC### begin -->
-<div class="typo3-fullDoc">
-       <div id="typo3-docheader">
-               <div class="typo3-docheader-functions">
-                       <div class="left"></div>
-                       <div class="right">
-                               <f:be.pagePath /><f:be.pageInfo />
-                       </div>
-               </div>
-               <div class="typo3-docheader-buttons">
-                       <div class="left">
-                               <f:if condition="{showPreviewLink}">
-                                       <a href="#" onclick="TYPO3.Workspaces.Actions.generateWorkspacePreviewLinksForAllLanguages();return false;" title="{f:translate(key:'tooltip.generatePagePreview')}" id="goPreviewLinkButton">
-                                               <span class="t3-icon t3-icon-extensions t3-icon-extensions-workspaces t3-icon-workspaces-generatepreviewlink">&nbsp;</span>
-                                               <f:translate key="label_doaction_generatePreviewLinks">Generate Workspace Preview Links</f:translate>
-                                       </a>
-                               </f:if>
-                       </div>
-                       <div class="right">
-                               <f:be.buttons.shortcut />
-                       </div>
-               </div>
-       </div>
-</div>
-
-<div id="typo3-docbody">
-       <div id="typo3-inner-docbody">
-               <f:if condition="{pageTitle}"><h1>{pageTitle}</h1></f:if>
-               <f:flashMessages />
-               <div id="workspacetabs"></div>
-               <div class="well well-sm"><f:render section="main" /></div>
-               <f:if condition="{showLegend}"><f:render partial="legend" /></f:if>
-       </div>
-</div>
+<f:if condition="{pageTitle}"><h1>{pageTitle}</h1></f:if>
+<f:flashMessages />
+<div id="workspacetabs"></div>
+<div class="well well-sm"><f:render section="main" /></div>
+<f:if condition="{showLegend}"><f:render partial="legend" /></f:if>
\ No newline at end of file
index 54138fc..06c55c2 100644 (file)
@@ -43,6 +43,13 @@ if (TYPO3_MODE === 'BE' && !(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_INSTALL)) {
     );
 }
 
+// Registers preview link icon
+\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Imaging\IconRegistry::class)->registerIcon(
+    'module-workspaces-action-preview-link',
+    \TYPO3\CMS\Core\Imaging\IconProvider\BitmapIconProvider::class,
+    ['source' => 'EXT:workspaces/Resources/Public/Images/generate-ws-preview-link.png']
+);
+
 // @todo move icons to Core sprite or keep them here and remove the todo note ;)
 $icons = array(
     'sendtonextstage' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('workspaces') . 'Resources/Public/Images/version-workspace-sendtonextstage.png',