[TASK] Use ModuleTemplate API for EXT:viewpage 12/43812/4
authorMathias Schreiber <mathias.schreiber@wmdb.de>
Mon, 5 Oct 2015 10:10:19 +0000 (12:10 +0200)
committerFrans Saris <franssaris@gmail.com>
Tue, 6 Oct 2015 17:27:23 +0000 (19:27 +0200)
Releases: master
Resolves: #70365
Change-Id: I95315d1b713d28df0ec5f6fdde61eb2abc10a182
Reviewed-on: http://review.typo3.org/43812
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
typo3/sysext/viewpage/Classes/Controller/ViewModuleController.php
typo3/sysext/viewpage/Resources/Private/Layouts/DocHeader.html
typo3/sysext/viewpage/Resources/Public/JavaScript/Main.js

index 56a2de2..f3ae3c2 100644 (file)
@@ -14,14 +14,73 @@ namespace TYPO3\CMS\Viewpage\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Backend\Template\Components\ButtonBar;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Backend\View\BackendTemplateView;
+use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Page\PageRenderer;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
+use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
 
 /**
  * Controller for viewing the frontend
  */
-class ViewModuleController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
+class ViewModuleController extends ActionController {
+
+       /**
+        * @var string
+        */
+       protected $defaultViewObjectName = BackendTemplateView::class;
+
+       /**
+        * @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);
+               $this->registerButtons();
+       }
+
+       /**
+        * Registers the docheader buttons
+        */
+       protected function registerButtons() {
+               $iconFactory = $this->view->getModuleTemplate()->getIconFactory();
+               $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
+               $showButton = $buttonBar->makeLinkButton()
+                       ->setHref($this->getTargetUrl())
+                       ->setOnClick('window.open(this.href, \'newTYPO3frontendWindow\').focus();return false;')
+                       ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE))
+                       ->setIcon($iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL));
+               $buttonBar->addButton($showButton);
+
+               $refreshButton = $buttonBar->makeLinkButton()
+                       ->setHref('javascript:document.getElementById(\'tx_viewpage_iframe\').contentWindow.location.reload(true);')
+                       ->setTitle($this->getLanguageService()->sL('LLL:EXT:viewpage/Resources/Private/Language/locallang.xlf:refreshPage'))
+                       ->setIcon($iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL));
+               $buttonBar->addButton($refreshButton, ButtonBar::BUTTON_POSITION_RIGHT, 1);
+
+               $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);
+       }
 
        /**
         * Gets called before each action
@@ -52,6 +111,11 @@ class ViewModuleController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionContr
         */
        protected function getTargetUrl() {
                $pageIdToShow = (int)GeneralUtility::_GP('id');
+
+               $permissionClause = $this->getBackendUser()->getPagePermsClause(1);
+               $pageRecord = BackendUtility::readPageAccess($pageIdToShow, $permissionClause);
+               $this->view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation($pageRecord);
+
                $adminCommand = $this->getAdminCommand($pageIdToShow);
                $domainName = $this->getDomainName($pageIdToShow);
                $languageParameter = $this->getLanguageParameter();
index aea8c80..e06e27b 100644 (file)
@@ -1,47 +1,24 @@
 {namespace core=TYPO3\CMS\Core\ViewHelpers}
-<f:be.container
+<f:be.pageRenderer
        includeCssFiles="{
                0:'{f:uri.resource(path:\'Css/ui-lightness/jquery-ui-1.10.3.custom.min.css\')}',
                1:'{f:uri.resource(path:\'Css/main.css\')}'
        }"
        includeRequireJsModules="{
                0:'TYPO3/CMS/Viewpage/Main'
-       }">
-       <div class="typo3-fullDoc">
-               <div id="typo3-docheader">
-                       <div class="typo3-docheader-functions">
-                               <form>
-                                       <label for="width">
-                                               <f:translate key="width" />
-                                       </label>
-                                       <f:form.select options="{widths}" id="width" name="width" />
-                                       <f:if condition="{languages -> f:count()} > 1">
-                                               <label for="language">
-                                                       <f:translate key="language" />
-                                               </label>
-                                               <f:form.select options="{languages}" id="language" name="language" />
-                                       </f:if>
-                               </form>
-                       </div>
-                       <div class="typo3-docheader-buttons">
-                               <div class="left">
-                                       <a href="{url}" onclick="window.open(this.href, 'newTYPO3frontendWindow').focus();return false;" title="{f:translate(key: 'LLL:EXT:lang/locallang_core.xlf:labels.showPage')}">
-                                               <core:icon identifier="actions-document-view" />
-                                       </a>
-                               </div>
-                               <div class="right">
-                                       <a href="javascript:document.getElementById('tx_viewpage_iframe').contentWindow.location.reload(true);" title="{f:translate(key: 'refreshPage')}">
-                                               <core:icon identifier="actions-refresh" />
-                                       </a>
-                                       <f:be.buttons.shortcut/>
-                               </div>
-                       </div>
-               </div>
-
-               <div id="typo3-docbody">
-                       <div id="typo3-inner-docbody" class="tx_viewpage">
-                               <f:render section="Content" />
-                       </div>
-               </div>
-       </div>
-</f:be.container>
+       }" />
+<div class="tx_viewpage">
+       <form>
+               <label for="width">
+                       <f:translate key="width" />
+               </label>
+               <f:form.select options="{widths}" id="width" name="width" />
+               <f:if condition="{languages -> f:count()} > 1">
+                       <label for="language">
+                               <f:translate key="language" />
+                       </label>
+                       <f:form.select options="{languages}" id="language" name="language" />
+               </f:if>
+       </form>
+       <f:render section="Content" />
+</div>
\ No newline at end of file
index 4f940e2..1dec389 100644 (file)
@@ -37,9 +37,13 @@ define(['jquery', 'jquery-ui/resizable'], function($) {
                        var value = me.$widthSelector.val();
                        if (value) {
                                value = value.split('|');
+                               var height = value[1] || '100%';
+                               if (height === '100%') {
+                                       height = ViewPage.calculateContainerMaxHeight();
+                               }
                                me.$resizableContainer.animate({
                                        width:  value[0],
-                                       height: value[1] || '100%'
+                                       height: height
                                });
                                Storage.Persistent.set(me.storagePrefix + 'widthSelectorValue', value[0] + '|' + (value[1] || '100%'));
                        }
@@ -118,6 +122,15 @@ define(['jquery', 'jquery-ui/resizable'], function($) {
                });
        };
 
+       ViewPage.calculateContainerMaxHeight = function() {
+               ViewPage.$resizableContainer.hide();
+               var padding = $('.t3js-module-body').outerHeight() - $('.t3js-module-body').height(),
+                       controlsHeight = ViewPage.$widthSelector.parents('form:first').height(),
+                       documentHeight = $(document).height();
+               ViewPage.$resizableContainer.show();
+               return documentHeight - (controlsHeight + padding);
+       };
+
        ViewPage.addCustomWidthOption = function(value) {
                ViewPage.$widthSelector.prepend('<option id="customOption" value="' + value + '">' + ViewPage.getOptionLabel(value) + '</option>');
        };