Skip to content

Commit

Permalink
[BUGFIX] LinkViewHelper must set correct controller context (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminkott committed Feb 12, 2019
1 parent 4ab11f7 commit 11ad2f2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 33 deletions.
13 changes: 5 additions & 8 deletions Classes/ViewHelpers/Link/ArchiveViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,22 @@ public function render(): string
$year = (int)$this->arguments['year'];
$month = (int)$this->arguments['month'];
$pageUid = (int)$this->getTypoScriptFrontendController()->tmpl->setup['plugin.']['tx_blog.']['settings.']['archiveUid'];
$additionalParams = [
'tx_blog_archive' => [
'year' => $year,
],
$arguments = [
'year' => $year
];
if ($month > 0) {
$additionalParams['tx_blog_archive']['month'] = $month;
$arguments['month'] = $month;
}
$uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
$uriBuilder->reset()
->setTargetPageUid($pageUid)
->setUseCacheHash(true)
->setArguments($additionalParams);
->setUseCacheHash(true);
if ($rssFormat) {
$uriBuilder
->setFormat('rss')
->setTargetPageType($this->getTypoScriptFrontendController()->tmpl->setup['blog_rss_archive.']['typeNum']);
}
$uri = $uriBuilder->uriFor('listPostsByDate', [], 'Post', 'Blog');
$uri = $uriBuilder->uriFor('listPostsByDate', $arguments, 'Post', 'Blog', 'Archive');
if ($uri !== '') {
$this->tag->addAttribute('href', $uri);
$this->tag->setContent($this->renderChildren());
Expand Down
16 changes: 5 additions & 11 deletions Classes/ViewHelpers/Link/AuthorViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,11 @@ protected function buildUriFromDetailsPage(Author $author, bool $rssFormat)
*/
protected function buildUriFromDefaultPage(Author $author, bool $rssFormat)
{
$uriBuilder = $this->getUriBuilder(
(int)$this->getTypoScriptFrontendController()->tmpl->setup['plugin.']['tx_blog.']['settings.']['authorUid'],
[
'tx_blog_authorposts' => [
'author' => $author->getUid(),
],
],
$rssFormat
);

return $this->buildAnchorTag($uriBuilder->uriFor('listPostsByAuthor', [], 'Post'), $author, 'Blog');
$uriBuilder = $this->getUriBuilder((int)$this->getTypoScriptFrontendController()->tmpl->setup['plugin.']['tx_blog.']['settings.']['authorUid'], [], $rssFormat);
$arguments = [
'author' => $author->getUid(),
];
return $this->buildAnchorTag($uriBuilder->uriFor('listPostsByAuthor', $arguments, 'Post', 'Blog', 'AuthorPosts'), $author);
}

/**
Expand Down
11 changes: 4 additions & 7 deletions Classes/ViewHelpers/Link/CategoryViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,19 @@ public function render(): string
/** @var Category $category */
$category = $this->arguments['category'];
$pageUid = (int)$this->getTypoScriptFrontendController()->tmpl->setup['plugin.']['tx_blog.']['settings.']['categoryUid'];
$additionalParams = [
'tx_blog_category' => [
'category' => $category->getUid(),
],
$arguments = [
'category' => $category->getUid(),
];
$uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
$uriBuilder->reset()
->setTargetPageUid($pageUid)
->setUseCacheHash(true)
->setArguments($additionalParams);
->setUseCacheHash(true);
if ($rssFormat) {
$uriBuilder
->setFormat('rss')
->setTargetPageType($this->getTypoScriptFrontendController()->tmpl->setup['blog_rss_category.']['typeNum']);
}
$uri = $uriBuilder->uriFor('listPostsByCategory', [], 'Post', 'Blog');
$uri = $uriBuilder->uriFor('listPostsByCategory', $arguments, 'Post', 'Blog', 'Category');

if ($uri !== '') {
$linkText = $this->renderChildren() ?: $category->getTitle();
Expand Down
11 changes: 4 additions & 7 deletions Classes/ViewHelpers/Link/TagViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,19 @@ public function render(): string
/** @var Tag $tag */
$tag = $this->arguments['tag'];
$pageUid = (int)$this->getTypoScriptFrontendController()->tmpl->setup['plugin.']['tx_blog.']['settings.']['tagUid'];
$additionalParams = [
'tx_blog_tag' => [
'tag' => $tag->getUid(),
],
$arguments = [
'tag' => $tag->getUid(),
];
$uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
$uriBuilder->reset()
->setTargetPageUid($pageUid)
->setUseCacheHash(true)
->setArguments($additionalParams);
->setUseCacheHash(true);
if ($rssFormat) {
$uriBuilder
->setFormat('rss')
->setTargetPageType($this->getTypoScriptFrontendController()->tmpl->setup['blog_rss_tag.']['typeNum']);
}
$uri = $uriBuilder->uriFor('listPostsByTag', [], 'Post', 'Blog');
$uri = $uriBuilder->uriFor('listPostsByTag', $arguments, 'Post', 'Blog', 'Tag');
if ($uri !== '') {
$linkText = $this->renderChildren() ?: $tag->getTitle();
$this->tag->addAttribute('href', $uri);
Expand Down

0 comments on commit 11ad2f2

Please sign in to comment.