Skip to content

Commit

Permalink
[BUGFIX] Check if category does exist before accessing properties
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminkott committed May 13, 2019
1 parent 6aec95b commit 53fb359
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
9 changes: 4 additions & 5 deletions Classes/Controller/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,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)) {
Expand All @@ -241,9 +240,7 @@ 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);
Expand All @@ -253,6 +250,8 @@ public function listPostsByCategoryAction(Category $category = null): void
foreach ($posts as $post) {
$this->blogCacheService->addTagsForPost($post);
}
} else {
$this->view->assign('categories', $this->categoryRepository->findAll());
}
}

Expand Down
20 changes: 9 additions & 11 deletions Resources/Private/Templates/Post/ListPostsByCategory.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,8 @@
<f:layout name="Default" />

<f:section name="content">
<f:if condition="{categories}">
<f:if condition="{category}">
<f:then>
<f:comment>In case categories is set, to special category is in request and we show all categories as links.</f:comment>
<h1 class="page-title"><f:translate key="headline.categories" /></h1>
<ul class="list-inline">
<f:for each="{categories}" as="category">
<li><blog:link.category category="{category}" /></li>
</f:for>
</ul>
</f:then>
<f:else>
<f:comment>In case categories is NOT set, a special category is in request and we show all blogs posts of this category.</f:comment>
<h1 class="page-title"><f:translate key="headline.category" arguments="{0: category.title}" /> <blog:link.category rss="true" category="{category}"><i class="fa fa-rss-square"></i></blog:link.category></h1>
<div class="taxonomy-description">
<p>{category.description}</p>
Expand All @@ -22,6 +12,14 @@ <h1 class="page-title"><f:translate key="headline.category" arguments="{0: categ
</f:if>
</div>
<f:render partial="List" arguments="{_all}" />
</f:then>
<f:else>
<h1 class="page-title"><f:translate key="headline.categories" /></h1>
<ul class="list-inline">
<f:for each="{categories}" as="category">
<li><blog:link.category category="{category}" /></li>
</f:for>
</ul>
</f:else>
</f:if>
</f:section>
Expand Down

0 comments on commit 53fb359

Please sign in to comment.