From ec9cc899f64efbd11309ed2750688f6c7b0202bb Mon Sep 17 00:00:00 2001
From: Matthias Adrowski <matthias.adrowski@sgalinski.de>
Date: Mon, 10 Jan 2022 15:35:35 +0100
Subject: [PATCH] [TASK] Migrate BackendController

---
 Classes/Controller/AbstractController.php | 13 +++++++++++
 Classes/Controller/BackendController.php  | 27 +++++++++++++++++++----
 2 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/Classes/Controller/AbstractController.php b/Classes/Controller/AbstractController.php
index 1c710e0..52b9414 100644
--- a/Classes/Controller/AbstractController.php
+++ b/Classes/Controller/AbstractController.php
@@ -215,4 +215,17 @@ abstract class AbstractController extends ActionController {
 		}
 		return $offset;
 	}
+
+	/**
+	 * Build Typo3 11 Response
+	 * @param string|NULL $html
+	 * @return \Psr\Http\Message\ResponseInterface
+	 */
+	protected function htmlResponse(string $html = null): \Psr\Http\Message\ResponseInterface
+	{
+		return $this->responseFactory->createResponse()
+			->withHeader('Content-Type', 'text/html; charset=utf-8')
+			->withBody($this->streamFactory->createStream($html ?? $this->view->render()));
+	}
+
 }
diff --git a/Classes/Controller/BackendController.php b/Classes/Controller/BackendController.php
index 3db08d1..eb027af 100644
--- a/Classes/Controller/BackendController.php
+++ b/Classes/Controller/BackendController.php
@@ -131,12 +131,11 @@ class BackendController extends ActionController {
 	}
 
 	/**
-	 * @param array $filters
-	 * @throws \InvalidArgumentException
-	 * @throws \UnexpectedValueException
+	 * @param array|null $filters
+	 * @return \Psr\Http\Message\ResponseInterface|null
 	 * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
 	 */
-	public function indexAction(array $filters = NULL) {
+	public function indexAction(array $filters = NULL): ?\Psr\Http\Message\ResponseInterface {
 		$showNewsList = FALSE;
 		if (
 			($this->pageUid && $this->pageUid === $this->rootPageUid) ||
@@ -168,6 +167,13 @@ class BackendController extends ActionController {
 			$this->view->assign('alternativePageOptions', $alternativePageOptions);
 		}
 		$this->view->assign('showNewsList', $showNewsList);
+
+		if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) {
+			return NULL;
+		}
+		else {
+			return $this->createBackendResponse();
+		}
 	}
 
 	/**
@@ -236,4 +242,17 @@ class BackendController extends ActionController {
 		}
 		$this->docHeaderComponent->getMenuRegistry()->addMenu($languageMenu);
 	}
+
+
+	/**
+	 * Use the ModuleTemplateResponse to create a response object for the backend
+	 *
+	 * @return  \Psr\Http\Message\ResponseInterface
+	 */
+	protected function createBackendResponse():  \Psr\Http\Message\ResponseInterface
+	{
+		$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
+		$moduleTemplate->setContent($this->view->render());
+		return $this->htmlResponse($moduleTemplate->renderContent());
+	}
 }
-- 
GitLab