Skip to content

Commit

Permalink
[FIX] Use latest BE module template API (replace legacy view)
Browse files Browse the repository at this point in the history
  • Loading branch information
fnagel committed Mar 26, 2024
1 parent e39105d commit 3cfe6e8
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 25 deletions.
18 changes: 8 additions & 10 deletions Classes/Controller/AbstractBackendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,17 @@ protected function initializeView()
$dateTimeFormat = trim($this->settings['backend']['dateTimeFormat']);
}

$this->view->assignMultiple([
$this->moduleTemplate = $this->moduleTemplateFactory->create($this->request);

$this->moduleTemplate->assignMultiple([
'pageId' => $this->pageId,
'dateTimeFormat' => $dateTimeFormat,
'pageNotice' => $this->pageInfo,
]);

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

// Configure module header
$moduleService = GeneralUtility::makeInstance(
BackendModuleService::class,
$this->view,
$this->moduleTemplate,
$this->pageId
);
Expand Down Expand Up @@ -221,27 +220,26 @@ protected function initializeAction()
}
}

protected function moduleResponse(): ResponseInterface
protected function moduleResponse(string $templateFileName): ResponseInterface
{
$this->moduleTemplate->setContent($this->view->render());

return $this->htmlResponse($this->moduleTemplate->renderContent());
return $this->moduleTemplate->renderResponse('Backend'.$templateFileName);
}

protected function paginationHtmlResponse(
string $templateFileName,
QueryResultInterface $result,
array $paginationConfig,
int $page = 1
): ResponseInterface {
$paginator = new QueryResultPaginator($result, $page, (int)$paginationConfig['itemsPerPage'] ?: 10);

$this->view->assignMultiple([
$this->moduleTemplate->assignMultiple([
'totalAmountOfItems' => $result->count(),
'paginator' => $paginator,
'pagination' => new SimplePagination($paginator),
]);

return $this->moduleResponse();
return $this->moduleResponse($templateFileName);
}

/**
Expand Down
8 changes: 6 additions & 2 deletions Classes/Controller/BackendCommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ class BackendCommentController extends AbstractBackendController
*/
public function indexAction(int $page = 1): ResponseInterface
{
$this->view->assign('pendingCommentsCount', $this->commentRepository->countPendingByPage($this->pageId));
$this->moduleTemplate->assign('pendingCommentsCount', $this->commentRepository->countPendingByPage($this->pageId));

return $this->response(
'Index',
$this->commentRepository->findByPage($this->pageId),
$page
);
Expand All @@ -38,6 +39,7 @@ public function indexAction(int $page = 1): ResponseInterface
public function listPendingAction(int $page = 1): ResponseInterface
{
return $this->response(
'ListPending',
$this->commentRepository->findPendingByPage($this->pageId),
$page
);
Expand All @@ -54,14 +56,16 @@ public function listByPostAction(Post $post, int $page = 1): ResponseInterface
]);

return $this->response(
'ListByPost',
$this->commentRepository->findByPost($post, false),
$page
);
}

protected function response(QueryResultInterface $result, int $page = 1): ResponseInterface
protected function response(string $templateFileName, QueryResultInterface $result, int $page = 1): ResponseInterface
{
return $this->paginationHtmlResponse(
'Comment/'.$templateFileName,
$result,
$this->settings['backend']['comments']['paginate'],
$page
Expand Down
6 changes: 3 additions & 3 deletions Classes/Controller/BackendDashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class BackendDashboardController extends AbstractBackendController
public function indexAction(): ResponseInterface
{
if (!isset($this->settings['backend'])) {
return $this->moduleResponse();
return $this->moduleResponse('Dashboard/Index');
}

$settings = $this->settings['backend']['dashboard'];

$this->view->assignMultiple([
$this->moduleTemplate->assignMultiple([
'postDrafts' => $this->postRepository->findDrafts(
$this->pageId,
(int)$settings['postDrafts']['paginate']['itemsPerPage']
Expand Down Expand Up @@ -55,6 +55,6 @@ public function indexAction(): ResponseInterface
'validBlogSubscribersCount' => $this->blogSubscriberRepository->findByPage($this->pageId)->count(),
]);

return $this->moduleResponse();
return $this->moduleResponse('Dashboard/Index');
}
}
1 change: 1 addition & 0 deletions Classes/Controller/BackendPostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class BackendPostController extends AbstractBackendController
public function indexAction(int $page = 1): ResponseInterface
{
return $this->paginationHtmlResponse(
'Post/Index',
$this->postRepository->findByPage($this->pageId, false),
$this->settings['backend']['posts']['paginate'],
$page
Expand Down
2 changes: 2 additions & 0 deletions Classes/Controller/BackendSubscriberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class BackendSubscriberController extends AbstractBackendController
public function indexPostSubscriberAction(int $page = 1): ResponseInterface
{
return $this->paginationHtmlResponse(
'Subscriber/IndexPostSubscriber',
$this->postSubscriberRepository->findByPage($this->pageId, false),
$this->settings['backend']['subscriber']['post']['paginate'],
$page
Expand All @@ -34,6 +35,7 @@ public function indexPostSubscriberAction(int $page = 1): ResponseInterface
public function indexBlogSubscriberAction(int $page = 1): ResponseInterface
{
return $this->paginationHtmlResponse(
'Subscriber/IndexBlogSubscriber',
$this->blogSubscriberRepository->findByPage($this->pageId, false),
$this->settings['backend']['subscriber']['blog']['paginate'],
$page
Expand Down
8 changes: 1 addition & 7 deletions Classes/Service/BackendModuleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Fluid\View\TemplateView as View;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
Expand All @@ -33,13 +32,8 @@ class BackendModuleService
{
/**
* BackendModuleService constructor.
*
*/
public function __construct(
protected View $view,
protected ModuleTemplate $moduleTemplate,
protected int $pid
) {
public function __construct(protected ModuleTemplate $moduleTemplate, protected int $pid) {
}

/**
Expand Down
11 changes: 8 additions & 3 deletions Resources/Private/Layouts/Backend.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
<html xmlns:f="http://typo3.org/ns/TYPO3/Fluid/ViewHelpers" data-namespace-typo3-fluid="true">

<div class="t3extblog">
<div class="module t3extblog" data-module-name="{moduleName}">
<f:render partial="DocHeader" arguments="{docHeader:docHeader}" />

<div class="module-body t3js-module-body">
<h1>
<f:translate key="module.title" />
<small>
<small class="text-body-secondary">
<f:render section="headline" optional="1" />
</small>
</h1>

<f:flashMessages />

<f:render partial="Backend/PageNotice" arguments="{data: pageNotice}" />

<f:render section="main" />
<f:render section="main" arguments="{_all}" />
</div>
</div>

</html>

0 comments on commit 3cfe6e8

Please sign in to comment.