Skip to content

Commit

Permalink
[TASK] Make BackendController compatible with v12
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminkott committed May 23, 2023
1 parent 388b433 commit ef00e7a
Showing 1 changed file with 19 additions and 61 deletions.
80 changes: 19 additions & 61 deletions Classes/Controller/BackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Fluid\View\StandaloneView;

class BackendController extends ActionController
{
Expand Down Expand Up @@ -79,9 +77,13 @@ protected function initializeDataTables(): void

public function setupWizardAction(): ResponseInterface
{
return $this->htmlResponse($this->render('Backend/SetupWizard.html', [
$this->view->assignMultiple([
'blogSetups' => $this->setupService->determineBlogSetups(),
]));
]);
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->setContent($this->view->render());

return $this->htmlResponse($moduleTemplate->renderContent());
}

public function postsAction(int $blogSetup = null): ResponseInterface
Expand All @@ -91,54 +93,36 @@ public function postsAction(int $blogSetup = null): ResponseInterface
$querySettings->setIgnoreEnableFields(true);
$this->postRepository->setDefaultQuerySettings($querySettings);

$html = $this->render('Backend/Posts.html', [
$this->view->assignMultiple([
'blogSetups' => $this->setupService->determineBlogSetups(),
'activeBlogSetup' => $blogSetup,
'posts' => $this->postRepository->findAllByPid($blogSetup),
]);
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->setContent($this->view->render());

$response = $this->responseFactory
->createResponse()
->withHeader('Content-Type', 'text/html; charset=utf-8');
$response
->getBody()
->write($html);

return $response;
return $this->htmlResponse($moduleTemplate->renderContent());
}

public function commentsAction(string $filter = null, int $blogSetup = null): ResponseInterface
{
$comments = [
'all' => $this->commentRepository->findAllByFilter(null, $blogSetup),
'pending' => $this->commentRepository->findAllByFilter('pending', $blogSetup),
'approved' => $this->commentRepository->findAllByFilter('approved', $blogSetup),
'declined' => $this->commentRepository->findAllByFilter('declined', $blogSetup),
'deleted' => $this->commentRepository->findAllByFilter('deleted', $blogSetup),
];

$html = $this->render('Backend/Comments.html', [
$this->view->assignMultiple([
'activeFilter' => $filter,
'activeBlogSetup' => $blogSetup,
'commentCounts' => [
'all' => $comments['all']->count(),
'pending' => $comments['pending']->count(),
'approved' => $comments['approved']->count(),
'declined' => $comments['declined']->count(),
'deleted' => $comments['deleted']->count(),
'all' => $this->commentRepository->findAllByFilter(null, $blogSetup)->count(),
'pending' => $this->commentRepository->findAllByFilter('pending', $blogSetup)->count(),
'approved' => $this->commentRepository->findAllByFilter('approved', $blogSetup)->count(),
'declined' => $this->commentRepository->findAllByFilter('declined', $blogSetup)->count(),
'deleted' => $this->commentRepository->findAllByFilter('deleted', $blogSetup)->count(),
],
'blogSetups' => $this->setupService->determineBlogSetups(),
'comments' => $this->commentRepository->findAllByFilter($filter, $blogSetup),
]);
$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->setContent($this->view->render());

$response = $this->responseFactory
->createResponse()
->withHeader('Content-Type', 'text/html; charset=utf-8');
$response
->getBody()
->write($html);

return $response;
return $this->htmlResponse($moduleTemplate->renderContent());
}

public function updateCommentStatusAction(string $status, string $filter = null, int $blogSetup = null, array $comments = [], int $comment = null): void
Expand Down Expand Up @@ -182,30 +166,4 @@ public function createBlogAction(array $data = null): void
}
$this->redirect('setupWizard');
}

protected function getFluidTemplateObject(string $templateNameAndPath): StandaloneView
{
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setLayoutRootPaths([GeneralUtility::getFileAbsFileName('EXT:blog/Resources/Private/Layouts')]);
$view->setPartialRootPaths([GeneralUtility::getFileAbsFileName('EXT:blog/Resources/Private/Partials')]);
$view->setTemplateRootPaths([GeneralUtility::getFileAbsFileName('EXT:blog/Resources/Private/Templates')]);
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName('EXT:blog/Resources/Private/Templates/' . $templateNameAndPath));
$view->setControllerContext($this->getControllerContext());
$view->getRequest()->setControllerExtensionName('Blog');

return $view;
}

protected function render(string $templateNameAndPath, array $values): string
{
$view = $this->getFluidTemplateObject($templateNameAndPath);
$view->assign('_template', $templateNameAndPath);
$view->assign('action', $this->actionMethodName);
$view->assignMultiple($values);

$moduleTemplate = $this->moduleTemplateFactory->create($this->request);
$moduleTemplate->setContent($view->render());

return $moduleTemplate->renderContent();
}
}

0 comments on commit ef00e7a

Please sign in to comment.