From 6675721bba23499761b73596053db872c3873949 Mon Sep 17 00:00:00 2001 From: Benjamin Kott Date: Mon, 13 May 2019 23:27:21 +0200 Subject: [PATCH] [BUGFIX] Check if category does exist before accessing properties --- Classes/Controller/PostController.php | 9 ++++----- .../Templates/Post/ListPostsByCategory.html | 20 +++++++++---------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Classes/Controller/PostController.php b/Classes/Controller/PostController.php index dbef53f3..e8569c77 100644 --- a/Classes/Controller/PostController.php +++ b/Classes/Controller/PostController.php @@ -202,11 +202,10 @@ public function listPostsByDateAction(int $year = null, int $month = null): void */ public function listPostsByCategoryAction(Category $category = null): void { - if (null === $category) { + if ($category === null) { $categories = $this->categoryRepository->getByReference( 'tt_content', $this->configurationManager->getContentObject()->data['uid'] - ); if (!empty($categories)) { @@ -215,15 +214,15 @@ public function listPostsByCategoryAction(Category $category = null): void } } - if (null === $category) { - $this->view->assign('categories', $this->categoryRepository->findAll()); - } else { + if ($category) { $posts = $this->postRepository->findAllByCategory($category); $this->view->assign('posts', $posts); $this->view->assign('category', $category); MetaService::set(MetaService::META_TITLE, $category->getTitle()); MetaService::set(MetaService::META_DESCRIPTION, $category->getDescription()); MetaService::set(MetaService::META_CATEGORIES, [$category->getTitle()]); + } else { + $this->view->assign('categories', $this->categoryRepository->findAll()); } } diff --git a/Resources/Private/Templates/Post/ListPostsByCategory.html b/Resources/Private/Templates/Post/ListPostsByCategory.html index 0e13a80e..472ae235 100644 --- a/Resources/Private/Templates/Post/ListPostsByCategory.html +++ b/Resources/Private/Templates/Post/ListPostsByCategory.html @@ -2,18 +2,8 @@ - + - In case categories is set, to special category is in request and we show all categories as links. -

-
    - -
  • -
    -
-
- - In case categories is NOT set, a special category is in request and we show all blogs posts of this category.

{category.description}

@@ -22,6 +12,14 @@

+ + +

+
    + +
  • +
    +