From 1db644be7b1b79925d66c6aaa22671bc0e7abed7 Mon Sep 17 00:00:00 2001 From: Kevin Ditscheid <kevin.ditscheid@sgalinski.de> Date: Fri, 1 Dec 2023 09:55:21 +0100 Subject: [PATCH] [BUGFIX] Fix backend module --- Classes/Controller/BackendController.php | 69 ++++++++++--------- Classes/Service/BackendService.php | 13 ++-- .../ViewHelpers/Backend/ControlViewHelper.php | 3 +- .../Private/Backend/Layouts/Default.html | 52 -------------- Resources/Private/Backend/Partials/Error.html | 3 - Resources/Private/Layouts/Backend.html | 45 ++++++++++++ .../Backend}/ButtonBar.html | 0 .../Backend}/CreateJob.html | 0 .../Partials => Partials/Backend}/Filter.html | 13 +++- .../Backend}/Pagination.html | 0 .../Backend}/SelectRoot.html | 0 .../Backend}/Index.html | 12 ++-- 12 files changed, 106 insertions(+), 104 deletions(-) delete mode 100644 Resources/Private/Backend/Layouts/Default.html delete mode 100644 Resources/Private/Backend/Partials/Error.html create mode 100644 Resources/Private/Layouts/Backend.html rename Resources/Private/{Backend/Partials => Partials/Backend}/ButtonBar.html (100%) rename Resources/Private/{Backend/Partials => Partials/Backend}/CreateJob.html (100%) rename Resources/Private/{Backend/Partials => Partials/Backend}/Filter.html (81%) rename Resources/Private/{Backend/Partials => Partials/Backend}/Pagination.html (100%) rename Resources/Private/{Backend/Partials => Partials/Backend}/SelectRoot.html (100%) rename Resources/Private/{Backend/Templates => Templates/Backend}/Index.html (83%) diff --git a/Classes/Controller/BackendController.php b/Classes/Controller/BackendController.php index 84f8133d..55b29360 100644 --- a/Classes/Controller/BackendController.php +++ b/Classes/Controller/BackendController.php @@ -26,18 +26,20 @@ namespace SGalinski\SgJobs\Controller; +use Doctrine\DBAL\Exception; use Psr\Http\Message\ResponseInterface; use SGalinski\SgJobs\Domain\Repository\CompanyRepository; use SGalinski\SgJobs\Domain\Repository\JobRepository; use SGalinski\SgJobs\Pagination\Pagination; use SGalinski\SgJobs\Service\BackendService; use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent; +use TYPO3\CMS\Backend\Template\ModuleTemplate; +use TYPO3\CMS\Backend\Template\ModuleTemplateFactory; use TYPO3\CMS\Backend\Utility\BackendUtility; use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\Mvc\Controller\ActionController; -use TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException; use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException; use TYPO3\CMS\Extbase\Persistence\QueryResultInterface; use TYPO3\CMS\Extbase\Utility\LocalizationUtility; @@ -51,36 +53,43 @@ class BackendController extends ActionController { * * @var DocHeaderComponent */ - protected $docHeaderComponent; + protected DocHeaderComponent $docHeaderComponent; /** * @var CompanyRepository * */ - protected $companyRepository; + protected CompanyRepository $companyRepository; /** * @var JobRepository * */ - protected $jobRepository; + protected JobRepository $jobRepository; /** - * Inject the CompanyRepository - * - * @param CompanyRepository $companyRepository + * @var ModuleTemplateFactory */ - public function injectCompanyRepository(CompanyRepository $companyRepository): void { - $this->companyRepository = $companyRepository; - } + protected ModuleTemplateFactory $moduleTemplateFactory; /** - * Inject the JobRepository - * - * @param JobRepository $jobRepository + * @var ModuleTemplate */ - public function injectJobRepository(JobRepository $jobRepository): void { + protected ModuleTemplate $moduleTemplate; + + public function __construct( + CompanyRepository $companyRepository, + JobRepository $jobRepository, + ModuleTemplateFactory $moduleTemplateFactory + ) { + $this->companyRepository = $companyRepository; $this->jobRepository = $jobRepository; + $this->moduleTemplateFactory = $moduleTemplateFactory; + } + + public function initializeAction(): void { + parent::initializeAction(); + $this->moduleTemplate = $this->moduleTemplateFactory->create($this->request); } /** @@ -89,10 +98,11 @@ class BackendController extends ActionController { * @param array $filters * @param int $currentPage * @return ResponseInterface - * @throws InvalidQueryException|NoSuchArgumentException + * @throws InvalidQueryException + * @throws Exception */ public function indexAction(array $filters = [], int $currentPage = 1): ResponseInterface { - $pageUid = (int) $this->request->getQueryParams()['id']; + $pageUid = $this->request->getQueryParams()['id'] ?? 0; $itemsPerPage = 10; /** @var BackendUserAuthentication $backendUser */ $backendUser = $GLOBALS['BE_USER']; @@ -111,25 +121,25 @@ class BackendController extends ActionController { $this->docHeaderComponent = GeneralUtility::makeInstance(DocHeaderComponent::class); $this->docHeaderComponent->setMetaInformation($pageInfo); BackendService::makeButtons($this->docHeaderComponent, $this->request); - $this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent()); + $this->moduleTemplate->assign('docHeader', $this->docHeaderComponent->docHeaderContent()); - $this->view->assign('pageUid', $pageUid); - $this->view->assign('pages', BackendService::getPagesWithJobRecords()); + $this->moduleTemplate->assign('pageUid', $pageUid); + $this->moduleTemplate->assign('pages', BackendService::getPagesWithJobRecords()); $jobsQueryResult = $this->jobRepository->findBackendJobs($pageUid, $filters, $itemsPerPage); $pagination = GeneralUtility::makeInstance(Pagination::class, $jobsQueryResult, $currentPage, $itemsPerPage); - $this->view->assign('pagination', $pagination); + $this->moduleTemplate->assign('pagination', $pagination); $totalJobCount = $pagination->getTotalItems(); - $this->view->assign('totalJobCount', $totalJobCount); + $this->moduleTemplate->assign('totalJobCount', $totalJobCount); // get all Locations /** @noinspection PhpUndefinedMethodInspection */ /** @var QueryResultInterface $companies */ $companies = $this->companyRepository->findByPid($pageUid); - $this->view->assign('locationOptions', $companies); + $this->moduleTemplate->assign('locationOptions', $companies); - $this->view->assign('isAdmin', $GLOBALS['BE_USER']->isAdmin()); - $this->view->assign('filters', $filters); + $this->moduleTemplate->assign('isAdmin', $GLOBALS['BE_USER']->isAdmin()); + $this->moduleTemplate->assign('filters', $filters); if (!$totalJobCount && $pageUid) { $this->addFlashMessage( LocalizationUtility::translate('backend.notice.noRecords', 'SgJobs'), @@ -138,15 +148,6 @@ class BackendController extends ActionController { ); } - return $this->createBackendResponse(); - } - - /** - * Use the ModuleTemplateResponse to create a response object for the backend - * - * @return ResponseInterface - */ - protected function createBackendResponse(): ResponseInterface { - return $this->htmlResponse($this->view->render()); + return $this->moduleTemplate->renderResponse('Index'); } } diff --git a/Classes/Service/BackendService.php b/Classes/Service/BackendService.php index 929b537e..3fa90cd4 100644 --- a/Classes/Service/BackendService.php +++ b/Classes/Service/BackendService.php @@ -50,12 +50,17 @@ class BackendService { */ public static function getPages(): array { $out = []; - $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages'); - $queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class)); + $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class) + ->getQueryBuilderForTable('pages'); + $queryBuilder->getRestrictions()->removeAll() + ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); $rows = $queryBuilder->select('*') ->from('pages') ->where( - $queryBuilder->expr()->eq('is_siteroot', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT)) + $queryBuilder->expr()->eq( + 'is_siteroot', + $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT) + ) )->executeQuery()->fetchAllAssociative(); foreach ($rows as $row) { @@ -85,7 +90,6 @@ class BackendService { * @throws \UnexpectedValueException */ public static function makeButtons($docHeaderComponent, $request): void { - /** @var ButtonBar $buttonBar */ $buttonBar = $docHeaderComponent->getButtonBar(); /** @var IconFactory $iconFactory */ $iconFactory = GeneralUtility::makeInstance(IconFactory::class); @@ -104,6 +108,7 @@ class BackendService { // shortcut button $shortcutButton = $buttonBar->makeShortcutButton() + ->setDisplayName('Shortcut') ->setRouteIdentifier($request->getPluginName()) ->setArguments( [ diff --git a/Classes/ViewHelpers/Backend/ControlViewHelper.php b/Classes/ViewHelpers/Backend/ControlViewHelper.php index 7ff7dea1..beadce81 100644 --- a/Classes/ViewHelpers/Backend/ControlViewHelper.php +++ b/Classes/ViewHelpers/Backend/ControlViewHelper.php @@ -65,6 +65,7 @@ class ControlViewHelper extends AbstractViewHelper { $GLOBALS['LANG']->includeLLFile('EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf'); $databaseRecordList = GeneralUtility::makeInstance(DatabaseRecordList::class); + $databaseRecordList->setRequest($this->renderingContext->getRequest()); $pageInfo = BackendUtility::readPageAccess($row['pid'], $GLOBALS['BE_USER']->getPagePermsClause(1)); $databaseRecordList->calcPerms = new Permission( $GLOBALS['BE_USER']->calcPerms($pageInfo) @@ -73,8 +74,6 @@ class ControlViewHelper extends AbstractViewHelper { $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class); $pageRenderer->loadJavaScriptModule('@typo3/backend/ajax-data-handler.js'); $pageRenderer->addInlineLanguageLabelFile('EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf'); - $languageService = GeneralUtility::makeInstance(LanguageService::class); - $languageService->includeLLFile('EXT:backend/Resources/Private/Language/locallang_alt_doc.xlf'); // DatabaseRecordList has a $prevPrevUid, which might track back a page. We won't do that, 1st+last record are // not sortable in one direction diff --git a/Resources/Private/Backend/Layouts/Default.html b/Resources/Private/Backend/Layouts/Default.html deleted file mode 100644 index 1f8de183..00000000 --- a/Resources/Private/Backend/Layouts/Default.html +++ /dev/null @@ -1,52 +0,0 @@ -{namespace core = TYPO3\CMS\Core\ViewHelpers} -{namespace sg=SGalinski\SgJobs\ViewHelpers} - - -<f:be.container - includeCssFiles="{0: '{f:uri.resource(path: \'StyleSheets/backend.css\')}'}" - includeRequireJsModules="{ -0: 'TYPO3/CMS/Backend/ContextMenu', -1: 'TYPO3/CMS/Backend/Tooltip', -2: 'TYPO3/CMS/SgJobs/Backend/SgJobs'}"> - <div class="module" data-module-id="" data-module-name=""> - <div class="module-docheader t3js-module-docheader"> - <div - class="module-docheader-bar module-docheader-bar-navigation t3js-module-docheader-bar t3js-module-docheader-bar-navigation"> - <div class="module-docheader-bar-column-left"> - </div> - <div class="module-docheader-bar-column-right"> - <span class="typo3-docheader-pagePath"> - <f:translate key="LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.path"/>: <f:format.raw>{docHeader.metaInformation.path}</f:format.raw> - </span> - <f:format.raw>{docHeader.metaInformation.recordInformation}</f:format.raw> - </div> - </div> - <div - class="module-docheader-bar module-docheader-bar-buttons t3js-module-docheader-bar t3js-module-docheader-bar-buttons"> - <div class="module-docheader-bar-column-left"> - <div class="btn-toolbar" role="toolbar" aria-label=""> - <f:render section="iconButtons"/> - </div> - </div> - <div class="module-docheader-bar-column-right"> - <f:render partial="ButtonBar" arguments="{buttons:docHeader.buttons.right}"/> - </div> - </div> - </div> - <f:if condition="{V11}"> - <f:then> - <div class="module-body t3js-module-body"> - </f:then> - <f:else> - <div id="typo3-docbody"> - </f:else> - </f:if> - <div id="typo3-inner-docbody"> - <h1> - <f:render section="headline"/> - </h1> - <f:render section="main"/> - </div> - </div> - </div> -</f:be.container> diff --git a/Resources/Private/Backend/Partials/Error.html b/Resources/Private/Backend/Partials/Error.html deleted file mode 100644 index a611c0d4..00000000 --- a/Resources/Private/Backend/Partials/Error.html +++ /dev/null @@ -1,3 +0,0 @@ -<div class="alert alert-danger"> - <strong>Error:</strong> <f:translate key="backend.message.error" /> -</div> \ No newline at end of file diff --git a/Resources/Private/Layouts/Backend.html b/Resources/Private/Layouts/Backend.html new file mode 100644 index 00000000..42fffa41 --- /dev/null +++ b/Resources/Private/Layouts/Backend.html @@ -0,0 +1,45 @@ +{namespace core = TYPO3\CMS\Core\ViewHelpers} +{namespace sg=SGalinski\SgJobs\ViewHelpers} + +<f:be.pageRenderer + includeCssFiles="{0: '{f:uri.resource(path: \'StyleSheets/backend.css\')}'}" + includeRequireJsModules="{ + 0: 'TYPO3/CMS/Backend/ContextMenu', + 1: 'TYPO3/CMS/Backend/Tooltip', + 2: 'TYPO3/CMS/SgJobs/Backend/SgJobs' + }" /> +<div class="module" data-module-id="" data-module-name=""> + <div class="module-docheader t3js-module-docheader"> + <div + class="module-docheader-bar module-docheader-bar-navigation t3js-module-docheader-bar t3js-module-docheader-bar-navigation"> + <div class="module-docheader-bar-column-left"> + </div> + <div class="module-docheader-bar-column-right"> + <span class="typo3-docheader-pagePath"> + <f:translate key="LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.path"/>: + <f:format.raw>{docHeader.metaInformation.path}</f:format.raw> + </span> + <f:format.raw>{docHeader.metaInformation.recordInformation}</f:format.raw> + </div> + </div> + <div + class="module-docheader-bar module-docheader-bar-buttons t3js-module-docheader-bar t3js-module-docheader-bar-buttons"> + <div class="module-docheader-bar-column-left"> + <div class="btn-toolbar" role="toolbar" aria-label=""> + <f:render section="iconButtons"/> + </div> + </div> + <div class="module-docheader-bar-column-right"> + <f:render partial="Backend/ButtonBar" arguments="{buttons:docHeader.buttons.right}"/> + </div> + </div> + </div> + <div class="module-body t3js-module-body"> + <div id="typo3-inner-docbody"> + <h1> + <f:render section="headline"/> + </h1> + <f:render section="main"/> + </div> + </div> +</div> diff --git a/Resources/Private/Backend/Partials/ButtonBar.html b/Resources/Private/Partials/Backend/ButtonBar.html similarity index 100% rename from Resources/Private/Backend/Partials/ButtonBar.html rename to Resources/Private/Partials/Backend/ButtonBar.html diff --git a/Resources/Private/Backend/Partials/CreateJob.html b/Resources/Private/Partials/Backend/CreateJob.html similarity index 100% rename from Resources/Private/Backend/Partials/CreateJob.html rename to Resources/Private/Partials/Backend/CreateJob.html diff --git a/Resources/Private/Backend/Partials/Filter.html b/Resources/Private/Partials/Backend/Filter.html similarity index 81% rename from Resources/Private/Backend/Partials/Filter.html rename to Resources/Private/Partials/Backend/Filter.html index ac0c65f0..affedb3f 100644 --- a/Resources/Private/Backend/Partials/Filter.html +++ b/Resources/Private/Partials/Backend/Filter.html @@ -1,12 +1,20 @@ {namespace be=TYPO3\CMS\Backend\ViewHelpers} -<f:form action="index" controller="Backend" method="post" objectName="filters" object="{filters}"> + +<f:form action="index" controller="Backend" method="post" objectName="filters"> <div class="row"> <div class="col-xs-6 col-6 col-sm-6"> <div class="form-group"> <label for="filter-locations"> <f:translate key="backend.filters.locations" /> </label> - <f:form.select class="form-control" multiple="1" size="4" property="locations" optionLabelField="name" optionValueField="city" options="{locationOptions}" id="filter-locations" /> + <f:form.select class="form-control" + multiple="1" + size="4" + property="locations" + optionLabelField="name" + optionValueField="city" + options="{locationOptions}" + id="filter-locations" /> <small> <f:format.raw><f:translate key="backend.filters.locations.description" /></f:format.raw> </small> @@ -30,6 +38,5 @@ </f:form.button> </div> </div> - </div> </f:form> diff --git a/Resources/Private/Backend/Partials/Pagination.html b/Resources/Private/Partials/Backend/Pagination.html similarity index 100% rename from Resources/Private/Backend/Partials/Pagination.html rename to Resources/Private/Partials/Backend/Pagination.html diff --git a/Resources/Private/Backend/Partials/SelectRoot.html b/Resources/Private/Partials/Backend/SelectRoot.html similarity index 100% rename from Resources/Private/Backend/Partials/SelectRoot.html rename to Resources/Private/Partials/Backend/SelectRoot.html diff --git a/Resources/Private/Backend/Templates/Index.html b/Resources/Private/Templates/Backend/Index.html similarity index 83% rename from Resources/Private/Backend/Templates/Index.html rename to Resources/Private/Templates/Backend/Index.html index 8533cc76..03f38698 100644 --- a/Resources/Private/Backend/Templates/Index.html +++ b/Resources/Private/Templates/Backend/Index.html @@ -1,7 +1,7 @@ {namespace sg=SGalinski\SgJobs\ViewHelpers} {namespace be=TYPO3\CMS\Backend\ViewHelpers} -<f:layout name="Default"/> +<f:layout name="Backend"/> <f:section name="iconButtons"> </f:section> @@ -14,8 +14,8 @@ <f:flashMessages /> <f:if condition="{pageUid}"> <f:then> - <f:render partial="Filter" arguments="{_all}"/> - <f:render partial="CreateJob" arguments="{_all}"/> + <f:render partial="Backend/Filter" arguments="{_all}"/> + <f:render partial="Backend/CreateJob" arguments="{_all}"/> <p> <f:translate key="backend.message.sorting"/> @@ -34,7 +34,7 @@ <thead> <tr> <td class="bg-light" colspan="3"> - <f:render partial="Pagination" arguments="{pagination: pagination}"/> + <f:render partial="Backend/Pagination" arguments="{pagination: pagination}"/> </td> </tr> </thead> @@ -67,9 +67,9 @@ </f:if> </f:then> <f:else> - <f:render partial="SelectRoot" arguments="{pages: pages}"/> + <f:render partial="Backend/SelectRoot" arguments="{pages: pages}"/> <f:if condition="{isAdmin}"> - <f:render partial="CreateJob" arguments="{pageUid: pageUid}"/> + <f:render partial="Backend/CreateJob" arguments="{pageUid: pageUid}"/> </f:if> </f:else> </f:if> -- GitLab