From 15b81cc0ba9b9fe278854f3213409221bfe8b4e9 Mon Sep 17 00:00:00 2001 From: Tobias Wojtylak Date: Fri, 17 Mar 2023 12:22:19 +0100 Subject: [PATCH 1/6] [TASK] remove `.` from action var name in PostController on rss feed --- Classes/Controller/PostController.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Classes/Controller/PostController.php b/Classes/Controller/PostController.php index c5b96a6e..0f58f269 100644 --- a/Classes/Controller/PostController.php +++ b/Classes/Controller/PostController.php @@ -117,26 +117,26 @@ protected function initializeView(ViewInterface $view): void { parent::initializeView($view); if ($this->request->getFormat() === 'rss') { - $action = '.' . $this->request->getControllerActionName(); + $action = $this->request->getControllerActionName(); $arguments = []; switch ($action) { - case '.listPostsByCategory': + case 'listPostsByCategory': if (isset($this->arguments['category'])) { $arguments[] = $this->arguments['category']->getValue()->getTitle(); } break; - case '.listPostsByDate': + case 'listPostsByDate': $arguments[] = (int)$this->arguments['year']->getValue(); if (isset($this->arguments['month'])) { $arguments[] = (int)$this->arguments['month']->getValue(); } break; - case '.listPostsByTag': + case 'listPostsByTag': if (isset($this->arguments['tag'])) { $arguments[] = $this->arguments['tag']->getValue()->getTitle(); } break; - case '.listPostsByAuthor': + case 'listPostsByAuthor': if (isset($this->arguments['author'])) { $arguments[] = $this->arguments['author']->getValue()->getName(); } @@ -145,8 +145,8 @@ protected function initializeView(ViewInterface $view): void } $feedData = [ - 'title' => LocalizationUtility::translate('feed.title' . $action, 'blog', $arguments), - 'description' => LocalizationUtility::translate('feed.description' . $action, 'blog', $arguments), + 'title' => LocalizationUtility::translate('feed.title.' . $action, 'blog', $arguments), + 'description' => LocalizationUtility::translate('feed.description.' . $action, 'blog', $arguments), 'language' => $this->getSiteLanguage()->getTwoLetterIsoCode(), 'link' => $this->getRequestUrl(), 'date' => date('r'), From b01ed456ed9a433ed910a08984cfe919c2898c7b Mon Sep 17 00:00:00 2001 From: Tobias Wojtylak Date: Mon, 20 Mar 2023 09:52:01 +0100 Subject: [PATCH 2/6] [TASK] return QueryResult in PostRepository::findByRepositoryDemand and move sort function to controller --- Classes/Controller/PostController.php | 27 +++++++++++++++++++- Classes/Domain/Repository/PostRepository.php | 21 +++------------ 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/Classes/Controller/PostController.php b/Classes/Controller/PostController.php index 0f58f269..bc0f0e76 100644 --- a/Classes/Controller/PostController.php +++ b/Classes/Controller/PostController.php @@ -188,11 +188,17 @@ public function listRecentPostsAction(int $currentPage = 1): ResponseInterface public function listByDemandAction(): ResponseInterface { $repositoryDemand = $this->postRepositoryDemandFactory->createFromSettings($this->settings['demand'] ?? []); + $posts = $this->postRepository->findByRepositoryDemand($repositoryDemand); + + if ([] !== $repositoryDemand->getPosts()) { + $posts = $this->sortPostsByManualOrder($posts, $repositoryDemand->getPosts()); + } $this->view->assign('type', 'demand'); $this->view->assign('demand', $repositoryDemand); - $this->view->assign('posts', $this->postRepository->findByRepositoryDemand($repositoryDemand)); + $this->view->assign('posts', $posts); $this->view->assign('pagination', []); + return $this->htmlResponse(); } @@ -473,4 +479,23 @@ protected function getPagination(QueryResultInterface $objects, int $currentPage $paginator = new QueryResultPaginator($objects, $currentPage, $itemsPerPage); return new BlogPagination($paginator, $maximumNumberOfLinks); } + + /** + * @param Post[] $posts + * @param int[] $postUids + * + * @return Post[] + */ + protected function sortPostsByManualOrder(array $posts, array $postUids): array + { + // Sort manually selected posts by defined order in group field + $sortedPosts = array_flip($postUids); + foreach ($posts as $post) { + $sortedPosts[$post->getUid()] = $post; + } + + return array_values(array_filter($sortedPosts, static function ($value) { + return $value instanceof Post; + })); + } } diff --git a/Classes/Domain/Repository/PostRepository.php b/Classes/Domain/Repository/PostRepository.php index f23e1a55..7308a881 100644 --- a/Classes/Domain/Repository/PostRepository.php +++ b/Classes/Domain/Repository/PostRepository.php @@ -73,9 +73,10 @@ public function findByUidRespectQuerySettings(int $uid) /** * @param PostRepositoryDemand $repositoryDemand; - * @return Post[] + * + * @return Post[]|\TYPO3\CMS\Extbase\Persistence\QueryResultInterface */ - public function findByRepositoryDemand(PostRepositoryDemand $repositoryDemand): array + public function findByRepositoryDemand(PostRepositoryDemand $repositoryDemand) { $query = $this->createQuery(); @@ -113,21 +114,7 @@ public function findByRepositoryDemand(PostRepositoryDemand $repositoryDemand): $query->setLimit($limit); } - /** @var Post[] $result */ - $result = $query->execute()->toArray(); - - if ($repositoryDemand->getPosts() !== []) { - // Sort manually selected posts by defined order in group field - $sortedPosts = array_flip($repositoryDemand->getPosts()); - foreach ($result as $post) { - $sortedPosts[$post->getUid()] = $post; - } - $result = array_values(array_filter($sortedPosts, function ($value) { - return $value instanceof Post; - })); - } - - return $result; + return $query->execute(); } /** From a68516d133cb889ae1a51a0365c1f9cb7d97be82 Mon Sep 17 00:00:00 2001 From: Tobias Wojtylak Date: Mon, 20 Mar 2023 11:17:07 +0100 Subject: [PATCH 3/6] [FEATURE] Handle demand setting for rss feed --- Classes/Controller/PostController.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Classes/Controller/PostController.php b/Classes/Controller/PostController.php index bc0f0e76..40d4a545 100644 --- a/Classes/Controller/PostController.php +++ b/Classes/Controller/PostController.php @@ -141,7 +141,9 @@ protected function initializeView(ViewInterface $view): void $arguments[] = $this->arguments['author']->getValue()->getName(); } break; - default: + case ([] !== ($this->settings['demand'] ?? [])): + $this->actionMethodName = 'listByDemandAction'; + break; } $feedData = [ @@ -185,19 +187,22 @@ public function listRecentPostsAction(int $currentPage = 1): ResponseInterface * @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException */ - public function listByDemandAction(): ResponseInterface + public function listByDemandAction(int $currentPage = 1): ResponseInterface { $repositoryDemand = $this->postRepositoryDemandFactory->createFromSettings($this->settings['demand'] ?? []); $posts = $this->postRepository->findByRepositoryDemand($repositoryDemand); if ([] !== $repositoryDemand->getPosts()) { $posts = $this->sortPostsByManualOrder($posts, $repositoryDemand->getPosts()); + $pagination = []; + } else { + $pagination = $this->getPagination($posts, $currentPage); } $this->view->assign('type', 'demand'); $this->view->assign('demand', $repositoryDemand); $this->view->assign('posts', $posts); - $this->view->assign('pagination', []); + $this->view->assign('pagination', $pagination); return $this->htmlResponse(); } From e9e3a6c8434054b5a43bf98b3cd363b3e83a396c Mon Sep 17 00:00:00 2001 From: Tobias Wojtylak Date: Mon, 20 Mar 2023 12:34:19 +0100 Subject: [PATCH 4/6] [FEATURE] allow PostRepositoryDemand ordering via settings array --- Classes/Factory/PostRepositoryDemandFactory.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Classes/Factory/PostRepositoryDemandFactory.php b/Classes/Factory/PostRepositoryDemandFactory.php index 2fd04476..83ff563d 100644 --- a/Classes/Factory/PostRepositoryDemandFactory.php +++ b/Classes/Factory/PostRepositoryDemandFactory.php @@ -57,7 +57,10 @@ public function createFromSettings(array $settings): PostRepositoryDemand $demand->setTagsConjunction($settings['tagsConjunction']); } - if (isset($GLOBALS['TCA']['pages']['columns'][$settings['sortBy']])) { + if ('' !== ($settings['ordering'] ?? null)) { + $ordering = explode(' ', $settings['ordering']); + $demand->setOrdering($ordering[0], $ordering[1] ?? 'ASC'); + } else if (isset($GLOBALS['TCA']['pages']['columns'][$settings['sortBy']])) { $direction = strtoupper($settings['sortDirection'] ?? 'ASC'); if (!in_array($direction, ['ASC', 'DESC'], true)) { $direction = 'ASC'; From 0c3841d27a3c01cdaa9631096b8e0b76b39bf794 Mon Sep 17 00:00:00 2001 From: Tobias Wojtylak Date: Mon, 20 Mar 2023 12:34:43 +0100 Subject: [PATCH 5/6] [TASK] Add documentation section for custom rss feed configuration --- Documentation/Configuration/Index.rst | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Documentation/Configuration/Index.rst b/Documentation/Configuration/Index.rst index a11b2f66..0af11fd6 100644 --- a/Documentation/Configuration/Index.rst +++ b/Documentation/Configuration/Index.rst @@ -1683,3 +1683,20 @@ plugin.tx_blog.settings.meta.listfooter.elements.comments.enable Description **Show comments in the meta section:** +TYPO3 Blog: RSS Feed +-------------------- + +Custom configuration +^^^^^^^^^^^^^^^^^^^^ + +You can modify the rss feed configuration by setting the `PostRepositoryDemand` DTO via TypoScript for the rss feed pagetype + +.. code-block:: typoscript + +[getTSFE().type == 200] + plugin.tx_blog.settings.demand { + categories = 15,153,158,151,16,87,251,88,18,22,89,19 + categoriesConjunction = OR + ordering = publish_date DESC + } +[end] From e0c75d36fc7308fb5d09474d0a69ad443ded9cfd Mon Sep 17 00:00:00 2001 From: Tobias Wojtylak Date: Tue, 21 Mar 2023 09:04:15 +0100 Subject: [PATCH 6/6] [TASK] allow overriding itemsPerPage (default: 10) for other formats than html (e.g. `rss`) in PostController pagination --- Classes/Controller/PostController.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Classes/Controller/PostController.php b/Classes/Controller/PostController.php index 40d4a545..d7572e2b 100644 --- a/Classes/Controller/PostController.php +++ b/Classes/Controller/PostController.php @@ -476,10 +476,7 @@ private function getRequestUrl(): string protected function getPagination(QueryResultInterface $objects, int $currentPage = 1): ?BlogPagination { $maximumNumberOfLinks = (int) ($this->settings['lists']['pagination']['maximumNumberOfLinks'] ?? 0); - $itemsPerPage = 10; - if ($this->request->getFormat() === 'html') { - $itemsPerPage = (int) ($this->settings['lists']['pagination']['itemsPerPage'] ?? 10); - } + $itemsPerPage = (int) ($this->settings['lists']['pagination']['itemsPerPage'] ?? 10); $paginator = new QueryResultPaginator($objects, $currentPage, $itemsPerPage); return new BlogPagination($paginator, $maximumNumberOfLinks);