Skip to content

Commit

Permalink
refactor: modernise backend controller
Browse files Browse the repository at this point in the history
related: #10
  • Loading branch information
brotkrueml committed Aug 27, 2024
1 parent 8588556 commit 385043b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
28 changes: 6 additions & 22 deletions Classes/Controller/ListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,17 @@
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Template\ModuleTemplateFactory;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Http\HtmlResponse;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;

/**
* @internal
*/
#[AsController]
final class ListController
{
private ModuleTemplate $moduleTemplate;
private StandaloneView $view;

public function __construct(
private readonly IconFactory $iconFactory,
private readonly ModuleTemplateFactory $moduleTemplateFactory,
Expand All @@ -50,41 +44,31 @@ public function __construct(

public function handleRequest(ServerRequestInterface $request): ResponseInterface
{
$this->moduleTemplate = $this->moduleTemplateFactory->create($request);
$view = $this->moduleTemplateFactory->create($request);

$this->pageRenderer->addCssFile('EXT:' . Extension::KEY . '/Resources/Public/Css/styles.css');
$this->pageRenderer->loadJavaScriptModule(
'@jobrouter/process/process-table-fields-toggler.js',
);

$this->initializeView();

$processDemands = $this->processDemandFactory->createMultiple(
$this->processRepository->findAll(true),
true,
);

$this->view->assign('processDemands', $processDemands);

$this->configureDocHeader(
$view,
$request->getAttribute('normalizedParams')?->getRequestUri() ?? '',
);

$this->moduleTemplate->setContent($this->view->render());
$view->assign('processDemands', $processDemands);

return new HtmlResponse($this->moduleTemplate->renderContent());
}

private function initializeView(): void
{
$this->view = GeneralUtility::makeInstance(StandaloneView::class);
$this->view->setTemplate('List');
$this->view->setTemplateRootPaths(['EXT:' . Extension::KEY . '/Resources/Private/Templates/Backend']);
return $view->renderResponse('Backend/List');
}

private function configureDocHeader(string $requestUri): void
private function configureDocHeader(ModuleTemplate $view, string $requestUri): void
{
$buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
$buttonBar = $view->getDocHeaderComponent()->getButtonBar();

$newProcessButton = $buttonBar->makeLinkButton()
->setHref((string) $this->uriBuilder->buildUriFromRoute(
Expand Down
8 changes: 6 additions & 2 deletions Resources/Private/Templates/Backend/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
data-namespace-typo3-fluid="true"
>

<h1><f:translate key="LLL:EXT:jobrouter_process/Resources/Private/Language/BackendModule.xlf:heading_text"/></h1>
<f:layout name="Module"/>

<f:render section="processDemands" arguments="{processDemands: processDemands}"/>
<f:section name="Content">
<h1><f:translate key="LLL:EXT:jobrouter_process/Resources/Private/Language/BackendModule.xlf:heading_text"/></h1>

<f:render section="processDemands" arguments="{processDemands: processDemands}"/>
</f:section>

<f:section name="processDemands">
<h2><f:translate key="LLL:EXT:jobrouter_process/Resources/Private/Language/BackendModule.xlf:processDemands_title"/></h2>
Expand Down

0 comments on commit 385043b

Please sign in to comment.