From 6f5c001251c733b477068b957dab042462deaa62 Mon Sep 17 00:00:00 2001 From: Lina Wolf <48202465+linawolf@users.noreply.github.com> Date: Mon, 17 Jun 2024 09:53:48 +0200 Subject: [PATCH] [TASK] Update and Improve Backend UriBuilder examples (#276) Move link examples to Partials so they can be included individually --- Classes/Controller/ModuleController.php | 110 ++++++++++-------- .../Partials/Module/CreateHaikuBlankLink.html | 10 ++ .../Partials/Module/CreateHaikuLink.html | 9 ++ .../Partials/Module/EditPage1Link.html | 9 ++ .../Partials/Module/EditPage2Link.html | 10 ++ Resources/Private/Templates/Module/Links.html | 17 +-- 6 files changed, 105 insertions(+), 60 deletions(-) create mode 100644 Resources/Private/Partials/Module/CreateHaikuBlankLink.html create mode 100644 Resources/Private/Partials/Module/CreateHaikuLink.html create mode 100644 Resources/Private/Partials/Module/EditPage1Link.html create mode 100644 Resources/Private/Partials/Module/EditPage2Link.html diff --git a/Classes/Controller/ModuleController.php b/Classes/Controller/ModuleController.php index bb7eba5..5845593 100644 --- a/Classes/Controller/ModuleController.php +++ b/Classes/Controller/ModuleController.php @@ -17,6 +17,7 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use Psr\Http\Message\UriInterface; use Psr\Log\LoggerInterface; use T3docs\Examples\Service\TableInformationService; use TYPO3\CMS\Backend\Clipboard\Clipboard; @@ -52,7 +53,7 @@ class ModuleController extends ActionController { private int $pageUid; - /** @var array */ + /** @var array */ private array $exampleConfig; public function __construct( @@ -64,7 +65,8 @@ public function __construct( protected readonly FileRepository $fileRepository, protected readonly ConnectionPool $connectionPool, protected readonly TableInformationService $tableInformationService, - private readonly LoggerInterface $logger, + protected readonly LoggerInterface $logger, + protected readonly UriBuilder $backendUriBuilder, ) {} /** @@ -296,72 +298,88 @@ protected function debugClipboard(): void */ public function linksAction(): ResponseInterface { - $backendUriBuilder = GeneralUtility::makeInstance(UriBuilder::class); - $uriParameters = ['edit' => ['pages' => [1 => 'edit']]]; - $editPage1Link = $backendUriBuilder->buildUriFromRoute( - 'record_edit', - $uriParameters, - ); $pageUid = (int)($this->request->getQueryParams()['id'] ?? 0); - $returnUrl = (string)$backendUriBuilder->buildUriFromRoute( + $returnUrl = (string)$this->backendUriBuilder->buildUriFromRoute( 'web_examples', ['id' => $pageUid, 'action' => 'links'], ); - $uriParameters = + $editPage1Link = $this->getEditPageLink(1, $returnUrl); + $editPagesDoktypeLink = $this->getEditDoktypeLink($returnUrl); + $createHaikuLink = $this->getCreateHaikuLink($returnUrl); + + $view = $this->initializeModuleTemplate($this->request); + $view->assignMultiple( [ - 'edit' => - [ - 'pages' => - [ - 1 => 'edit', - 2 => 'edit', - ], - 'tx_examples_haiku' => - [ - 1 => 'edit', - ], - ], - 'columnsOnly' => 'title,doktype', + 'editPage1Link' => $editPage1Link, + 'editPagesDoktypeLink' => $editPagesDoktypeLink, + 'createHaikuLink' => $createHaikuLink, 'returnUrl' => $returnUrl, - ]; - $editPagesDoktypeLink = $backendUriBuilder->buildUriFromRoute( + ], + ); + return $view->renderResponse(); + } + + private function getEditPageLink(int $uid, string $returnUrl): UriInterface + { + $uriParameters = [ + 'edit' => [ + 'pages' => [ + $uid => 'edit', + ], + ], + 'returnUrl' => $returnUrl, + ]; + return $this->backendUriBuilder->buildUriFromRoute( 'record_edit', $uriParameters, ); + } + + protected function getCreateHaikuLink(string $returnUrl): UriInterface + { $uriParameters = [ - 'edit' => - [ - 'tx_examples_haiku' => - [ - 1 => 'new', - ], + 'edit' => [ + 'tx_examples_haiku' => [ + 1 => 'new', ], - 'defVals' => - [ - 'tx_examples_haiku' => - [ - 'title' => 'New Haiku?', - 'season' => 'Spring', - ], + ], + 'defVals' => [ + 'tx_examples_haiku' => [ + 'title' => 'New Haiku?', + 'season' => 'Spring', ], + ], 'columnsOnly' => 'title,season,color', + 'returnUrl' => $returnUrl, ]; - $createHaikuLink = $backendUriBuilder->buildUriFromRoute( + return $this->backendUriBuilder->buildUriFromRoute( 'record_edit', $uriParameters, ); + } - $view = $this->initializeModuleTemplate($this->request); - $view->assignMultiple( + protected function getEditDoktypeLink(string $returnUrl): UriInterface + { + $uriParameters = [ - 'editPage1Link' => $editPage1Link, - 'editPagesDoktypeLink' => $editPagesDoktypeLink, - 'createHaikuLink' => $createHaikuLink, - ], + 'edit' => [ + 'pages' => [ + 1 => 'edit', + 2 => 'edit', + ], + 'tx_examples_haiku' => [ + 1 => 'edit', + ], + ], + 'columnsOnly' => 'title,doktype', + 'returnUrl' => $returnUrl, + ]; + return $this->backendUriBuilder->buildUriFromRoute( + 'record_edit', + $uriParameters, ); - return $view->renderResponse(); } /** diff --git a/Resources/Private/Partials/Module/CreateHaikuBlankLink.html b/Resources/Private/Partials/Module/CreateHaikuBlankLink.html new file mode 100644 index 0000000..4078114 --- /dev/null +++ b/Resources/Private/Partials/Module/CreateHaikuBlankLink.html @@ -0,0 +1,10 @@ + + + + + + diff --git a/Resources/Private/Partials/Module/CreateHaikuLink.html b/Resources/Private/Partials/Module/CreateHaikuLink.html new file mode 100644 index 0000000..5c8e889 --- /dev/null +++ b/Resources/Private/Partials/Module/CreateHaikuLink.html @@ -0,0 +1,9 @@ + + + + + + diff --git a/Resources/Private/Partials/Module/EditPage1Link.html b/Resources/Private/Partials/Module/EditPage1Link.html new file mode 100644 index 0000000..520fcd0 --- /dev/null +++ b/Resources/Private/Partials/Module/EditPage1Link.html @@ -0,0 +1,9 @@ + + + + Edit page 1 + + diff --git a/Resources/Private/Partials/Module/EditPage2Link.html b/Resources/Private/Partials/Module/EditPage2Link.html new file mode 100644 index 0000000..9064df5 --- /dev/null +++ b/Resources/Private/Partials/Module/EditPage2Link.html @@ -0,0 +1,10 @@ + + + + Edit page 2 + + diff --git a/Resources/Private/Templates/Module/Links.html b/Resources/Private/Templates/Module/Links.html index 28d18d0..6a5a5bd 100644 --- a/Resources/Private/Templates/Module/Links.html +++ b/Resources/Private/Templates/Module/Links.html @@ -13,17 +13,10 @@

- - - 1 - +

- Would only output the uri: - - - 2 - +

@@ -32,17 +25,13 @@

- Would only output the uri:

- - - - +