Skip to content

Commit

Permalink
[TASK] Rework backend controller
Browse files Browse the repository at this point in the history
Related: #14
  • Loading branch information
brotkrueml committed Dec 26, 2022
1 parent 496ad1f commit f734ffb
Show file tree
Hide file tree
Showing 11 changed files with 309 additions and 347 deletions.
151 changes: 0 additions & 151 deletions Classes/Controller/BackendController.php

This file was deleted.

128 changes: 128 additions & 0 deletions Classes/Controller/TableListController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php

declare(strict_types=1);

/*
* This file is part of the "jobrouter_data" extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

namespace Brotkrueml\JobRouterData\Controller;

use Brotkrueml\JobRouterData\Domain\Model\Table;
use Brotkrueml\JobRouterData\Domain\Repository\TableRepository;
use Brotkrueml\JobRouterData\Extension;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
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;

final class TableListController
{
private ModuleTemplate $moduleTemplate;
private StandaloneView $view;

public function __construct(
private readonly IconFactory $iconFactory,
private readonly ModuleTemplateFactory $moduleTemplateFactory,
private readonly PageRenderer $pageRenderer,
private readonly TableRepository $tableRepository,
private readonly UriBuilder $uriBuilder,
) {
}

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

$this->pageRenderer->addInlineLanguageLabelFile(
\str_replace('LLL:', '', Extension::LANGUAGE_PATH_BACKEND_MODULE)
);
$this->pageRenderer->loadRequireJsModule('TYPO3/CMS/JobrouterData/TableTest');

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

$this->moduleTemplate->setContent($this->view->render());

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']);
}

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

$newButton = $buttonBar->makeLinkButton()
->setHref((string)$this->uriBuilder->buildUriFromRoute(
'record_edit',
[
'edit' => [
'tx_jobrouterdata_domain_model_table' => ['new'],
],
'returnUrl' => (string)$this->uriBuilder->buildUriFromRoute(Extension::MODULE_NAME),
]
))
->setTitle($this->getLanguageService()->sL(Extension::LANGUAGE_PATH_BACKEND_MODULE . ':action.add_table'))
->setShowLabelText(true)
->setIcon($this->iconFactory->getIcon('actions-add', Icon::SIZE_SMALL));
$buttonBar->addButton($newButton);

$reloadButton = $buttonBar->makeLinkButton()
->setHref($requestUri)
->setTitle($this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.reload'))
->setIcon($this->iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL));
$buttonBar->addButton($reloadButton, ButtonBar::BUTTON_POSITION_RIGHT);

if ($this->getBackendUser()->mayMakeShortcut()) {
$shortcutButton = $buttonBar->makeShortcutButton()
->setRouteIdentifier('jobrouter_data')
->setDisplayName($this->getLanguageService()->sL(Extension::LANGUAGE_PATH_BACKEND_MODULE . ':heading_text'));
$buttonBar->addButton($shortcutButton, ButtonBar::BUTTON_POSITION_RIGHT);
}
}

private function listAction(): void
{
$simpleTables = $this->tableRepository->findAllByTypeWithHidden(Table::TYPE_SIMPLE);
$customTables = $this->tableRepository->findAllByTypeWithHidden(Table::TYPE_CUSTOM_TABLE);
$formFinisherTables = $this->tableRepository->findAllByTypeWithHidden(Table::TYPE_FORM_FINISHER);
$otherTables = $this->tableRepository->findAllByTypeWithHidden(Table::TYPE_OTHER_USAGE);

$this->view->assignMultiple([
'simpleTables' => $simpleTables,
'customTables' => $customTables,
'formFinisherTables' => $formFinisherTables,
'otherTables' => $otherTables,
]);
}

private function getLanguageService(): LanguageService
{
return $GLOBALS['LANG'];
}

private function getBackendUser(): BackendUserAuthentication
{
return $GLOBALS['BE_USER'];
}
}
2 changes: 2 additions & 0 deletions Classes/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ final class Extension
{
public const KEY = 'jobrouter_data';

public const MODULE_NAME = 'jobrouter_data';

private const LANGUAGE_PATH = 'LLL:EXT:' . self::KEY . '/Resources/Private/Language/';
public const LANGUAGE_PATH_BACKEND_MODULE = self::LANGUAGE_PATH . 'BackendModule.xlf';
public const LANGUAGE_PATH_CONTENT_ELEMENT = self::LANGUAGE_PATH . 'ContentElement.xlf';
Expand Down
3 changes: 3 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ services:
description: 'Transmit data sets to JobData tables'
schedulable: true

Brotkrueml\JobRouterData\Controller\TableListController:
tags: [ 'backend.controller' ]

Brotkrueml\JobRouterData\Controller\TableTestController:
tags: [ 'backend.controller' ]

Expand Down
Binary file modified Documentation/_images/no-table-links-found.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions Documentation/module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ screen:
Create a table link
-------------------

To create a new table link, click the :guilabel:`+` button on the top menu bar,
which opens a form. Alternatively, you can use the :guilabel:`Create new table
link` button.
To create a new table link, click the :guilabel:`+ Add table link` button on the
upper menu bar, which opens a form. Alternatively, you can use the
:guilabel:`Create new table link` button.


.. _module-create-table-link-types:
Expand Down
4 changes: 0 additions & 4 deletions Resources/Private/Layouts/BackendAdministration.html

This file was deleted.

Loading

0 comments on commit f734ffb

Please sign in to comment.