Skip to content

Commit

Permalink
refactor: modernise backend controller
Browse files Browse the repository at this point in the history
related: #9
  • Loading branch information
brotkrueml committed Aug 22, 2024
1 parent 697d2b4 commit 89eb1b1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 51 deletions.
32 changes: 8 additions & 24 deletions Classes/Controller/ConnectionListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,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 ConnectionListController
{
private ModuleTemplate $moduleTemplate;
private StandaloneView $view;

public function __construct(
private readonly ConnectionRepository $connectionRepository,
private readonly FileService $fileService,
Expand All @@ -52,7 +46,7 @@ public function __construct(

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

$this->pageRenderer->addInlineLanguageLabelFile(
\str_replace('LLL:', '', Extension::LANGUAGE_PATH_BACKEND_MODULE),
Expand All @@ -62,25 +56,15 @@ public function handleRequest(ServerRequestInterface $request): ResponseInterfac
'@jobrouter/connector/connection-check.js',
);

$this->initializeView();
$this->configureDocHeader($request->getAttribute('normalizedParams')?->getRequestUri() ?? '');
$this->listAction();

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

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();

$newButton = $buttonBar->makeLinkButton()
->setHref((string)$this->uriBuilder->buildUriFromRoute(
Expand Down Expand Up @@ -111,7 +95,7 @@ private function configureDocHeader(string $requestUri): void
}
}

private function listAction(): void
private function listAction(ModuleTemplate $view): void
{
$connections = [];
try {
Expand All @@ -122,7 +106,7 @@ private function listAction(): void
$keyFileExists = false;
}

$this->view->assignMultiple([
$view->assignMultiple([
'connections' => $connections,
'keyFileExists' => $keyFileExists,
'clientVersion' => (new Version())->getVersion(),
Expand Down
58 changes: 31 additions & 27 deletions Resources/Private/Templates/Backend/List.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,38 @@
data-namespace-typo3-fluid="true"
>

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

<f:if condition="{keyFileExists}">
<f:then>
<f:if condition="{connections -> f:count()}">
<f:then>
<f:render section="table" arguments="{_all}" />
</f:then>
<f:else>
<f:be.infobox state="-1" title="{f:translate(key: 'LLL:EXT:jobrouter_connector/Resources/Private/Language/BackendModule.xlf:connections_not_found.title')}">
<p><f:translate key="LLL:EXT:jobrouter_connector/Resources/Private/Language/BackendModule.xlf:connections_not_found.message"/></p>
<be:link.newRecord class="btn btn-primary" table="tx_jobrouterconnector_domain_model_connection" returnUrl="{f:be.uri(route: 'jobrouter_connections')}">
<f:translate key="LLL:EXT:jobrouter_connector/Resources/Private/Language/BackendModule.xlf:connection_create"/>
</be:link.newRecord>
</f:be.infobox>
</f:else>
</f:if>
</f:then>
<f:else>
<f:be.infobox state="2" title="{f:translate(key: 'LLL:EXT:jobrouter_connector/Resources/Private/Language/BackendModule.xlf:keyfile_not_exists.title')}">
<p><f:translate key="LLL:EXT:jobrouter_connector/Resources/Private/Language/BackendModule.xlf:keyfile_not_exists.message"/></p>
</f:be.infobox>
</f:else>
</f:if>
<p class="text-end">
<f:translate key="LLL:EXT:jobrouter_connector/Resources/Private/Language/BackendModule.xlf:client_version"/>:
{clientVersion}
</p>
<f:section name="Content">
<h1><f:translate key="LLL:EXT:jobrouter_connector/Resources/Private/Language/BackendModule.xlf:heading_text"/></h1>

<f:if condition="{keyFileExists}">
<f:then>
<f:if condition="{connections -> f:count()}">
<f:then>
<f:render section="table" arguments="{_all}" />
</f:then>
<f:else>
<f:be.infobox state="-1" title="{f:translate(key: 'LLL:EXT:jobrouter_connector/Resources/Private/Language/BackendModule.xlf:connections_not_found.title')}">
<p><f:translate key="LLL:EXT:jobrouter_connector/Resources/Private/Language/BackendModule.xlf:connections_not_found.message"/></p>
<be:link.newRecord class="btn btn-primary" table="tx_jobrouterconnector_domain_model_connection" returnUrl="{f:be.uri(route: 'jobrouter_connections')}">
<f:translate key="LLL:EXT:jobrouter_connector/Resources/Private/Language/BackendModule.xlf:connection_create"/>
</be:link.newRecord>
</f:be.infobox>
</f:else>
</f:if>
</f:then>
<f:else>
<f:be.infobox state="2" title="{f:translate(key: 'LLL:EXT:jobrouter_connector/Resources/Private/Language/BackendModule.xlf:keyfile_not_exists.title')}">
<p><f:translate key="LLL:EXT:jobrouter_connector/Resources/Private/Language/BackendModule.xlf:keyfile_not_exists.message"/></p>
</f:be.infobox>
</f:else>
</f:if>
<p class="text-end">
<f:translate key="LLL:EXT:jobrouter_connector/Resources/Private/Language/BackendModule.xlf:client_version"/>:
{clientVersion}
</p>
</f:section>

<f:section name="table">
<table class="table table-striped table-hover">
Expand Down

0 comments on commit 89eb1b1

Please sign in to comment.