Skip to content

Commit

Permalink
[FEATURE] Add function to get all tags of all articles by one author (#…
Browse files Browse the repository at this point in the history
…119)

This change adds the list of tags an author has blog posts written for to the output of an author detail page.
  • Loading branch information
davidsteeb authored and benjaminkott committed Jan 16, 2020
1 parent a7eab9a commit c79856c
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 3 deletions.
18 changes: 18 additions & 0 deletions Classes/Domain/Model/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,4 +409,22 @@ public function setDetailsPage(int $page): self
$this->detailsPage = $page;
return $this;
}

/**
* Function to get all unique tags from all posts of the author.
*
* @return array $tags
*/
public function getAllTags(): array
{
$uniqueTags = [];
foreach ($this->getPosts() as $post) {
foreach ($post->getTags() as $tag) {
if (!array_key_exists($tag->getUid(), $uniqueTags)) {
$uniqueTags[$tag->getUid()] = $tag;
}
}
}
return $uniqueTags;
}
}
5 changes: 3 additions & 2 deletions Configuration/DataHandler/BlogSetupRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@

$data = [];

// Tag and Category relation
// Relations
$data['pages']['NEW_firstBlogPostPage']['tags'] = 'NEW_blogTagTYPO3';
$data['pages']['NEW_firstBlogPostPage']['categories'] = 'NEW_blogCategoryTYPO3';
$data['pages']['NEW_firstBlogPostPage']['authors'] = 'NEW_blogAuthor';
$data['pages']['NEW_firstBlogPostPage']['comments'] = 'NEW_blogComment';
$data['pages']['NEW_firstBlogPostPage']['authors'] = 'NEW_blogAuthor';
$data['tx_blog_domain_model_author']['NEW_blogAuthor']['posts'] = 'NEW_firstBlogPostPage';

return $data;
13 changes: 13 additions & 0 deletions Resources/Private/Scss/frontend/components/_taglist.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* Taglist
*/
.blogtaglist {
padding: 0;
margin: -.25rem!important;
list-style: none;
}
.blogtaglist__item {
display: inline-block;
vertical-align: middle;
margin: .25rem;
}
1 change: 1 addition & 0 deletions Resources/Private/Scss/frontend/frontend.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
@import "components/comment";
@import "components/list";
@import "components/pagination";
@import "components/taglist";
@import "components/widget";
@import "components/widgetlist";

Expand Down
9 changes: 9 additions & 0 deletions Resources/Private/Templates/Post/ListPostsByAuthor.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ <h1 class="page__title">
<div class="taxonomy-description">
<p>{author.bio}</p>
</div>
<f:if condition="{author.allTags}">
<div class="taxonomy-tags">
<ul class="blogtaglist">
<f:for each="{author.allTags}" as="tag">
<li class="blogtaglist__item"><blogvh:link.tag class="blogbadge" tag="{tag}"/></li>
</f:for>
</ul>
</div>
</f:if>
<f:render partial="List" arguments="{_all}" />
</f:then>
<f:else>
Expand Down
2 changes: 1 addition & 1 deletion Resources/Public/Css/frontend.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c79856c

Please sign in to comment.