diff --git a/Classes/Controller/ModuleController.php b/Classes/Controller/ModuleController.php index 30bcb19..cb09d47 100644 --- a/Classes/Controller/ModuleController.php +++ b/Classes/Controller/ModuleController.php @@ -17,8 +17,8 @@ use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; -use Psr\Log\LoggerAwareInterface; -use Psr\Log\LoggerAwareTrait; +use Psr\Http\Message\UriInterface; +use Psr\Log\LoggerInterface; use T3docs\Examples\Service\TableInformationService; use TYPO3\CMS\Backend\Clipboard\Clipboard; use TYPO3\CMS\Backend\Template\ModuleTemplate; @@ -51,9 +51,9 @@ */ class ModuleController extends ActionController implements LoggerAwareInterface { - use LoggerAwareTrait; private int $pageUid; + /** @var array */ private array $exampleConfig; public function __construct( @@ -65,6 +65,8 @@ public function __construct( protected readonly FileRepository $fileRepository, protected readonly ConnectionPool $connectionPool, protected readonly TableInformationService $tableInformationService, + protected readonly LoggerInterface $logger, + protected readonly UriBuilder $backendUriBuilder, ) {} /** @@ -294,72 +296,88 @@ protected function debugClipboard() */ public function linksAction(): ResponseInterface { - $backendUriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\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:

- - - - +