Skip to content

Commit

Permalink
[BUGFIX] Check if author does exist before accessing properties
Browse files Browse the repository at this point in the history
Releases: master, 9.1, 9.0, 8.7, 7.6
  • Loading branch information
benjaminkott committed May 13, 2019
1 parent 9a0643e commit 20efb0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
6 changes: 3 additions & 3 deletions Classes/Controller/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,7 @@ public function listPostsByCategoryAction(Category $category = null)
*/
public function listPostsByAuthorAction(Author $author = null)
{
if (null === $author) {
$this->view->assign('authors', $this->authorRepository->findAll());
} else {
if ($author) {
$posts = $this->postRepository->findAllByAuthor($author);
$this->view->assign('posts', $posts);
$this->view->assign('author', $author);
Expand All @@ -266,6 +264,8 @@ public function listPostsByAuthorAction(Author $author = null)
foreach ($posts as $post) {
$this->blogCacheService->addTagsForPost($post);
}
} else {
$this->view->assign('authors', $this->authorRepository->findAll());
}
}

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

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

0 comments on commit 20efb0e

Please sign in to comment.