[BUGFIX] Check View Object in EXT:documentation to prevent fatal errors 86/43986/2
authorMathias Schreiber <mathias.schreiber@wmdb.de>
Sun, 11 Oct 2015 15:21:51 +0000 (17:21 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 11 Oct 2015 18:51:57 +0000 (20:51 +0200)
Extbase fires initializeView even if no view is needed (for example if
an action redirects).
We check for the correct ViewObject first to prevent these errors.

Resolves: #70588
Releases: master
Change-Id: I033edb4a7797164af3ee315bcd1da455376bdffc
Reviewed-on: http://review.typo3.org/43986
Reviewed-by: Michael Oehlhof <typo3@oehlhof.de>
Tested-by: Michael Oehlhof <typo3@oehlhof.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/documentation/Classes/Controller/DocumentController.php

index f36f1d5..6488114 100644 (file)
@@ -73,37 +73,41 @@ class DocumentController extends ActionController
      */
     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'))
+        if ($view instanceof BackendTemplateView) {
+            /** @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($isDownloadActive);
-            $menu->addMenuItem($downloadMenuItem);
-        }
+                ->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);
+            $this->view->getModuleTemplate()->getDocHeaderComponent()->getMenuRegistry()->addMenu($menu);
+        }
     }
 
     /**