diff --git a/Build/phpstan.neon b/Build/phpstan.neon
index 4234060e..f304e13a 100644
--- a/Build/phpstan.neon
+++ b/Build/phpstan.neon
@@ -12,6 +12,7 @@ parameters:
ignoreErrors:
- "#Casting to string something that's already string.#"
+ - "#^Call to an undefined method TYPO3Fluid\\\\Fluid\\\\Core\\\\Rendering\\\\RenderingContextInterface\\:\\:getRequest\\(\\)\\.$#"
paths:
- %currentWorkingDirectory%/Classes/
diff --git a/Classes/ViewHelpers/Link/AuthorViewHelper.php b/Classes/ViewHelpers/Link/AuthorViewHelper.php
index f434cd9f..ad603aa4 100644
--- a/Classes/ViewHelpers/Link/AuthorViewHelper.php
+++ b/Classes/ViewHelpers/Link/AuthorViewHelper.php
@@ -13,6 +13,7 @@
use T3G\AgencyPack\Blog\Domain\Model\Author;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
+use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
class AuthorViewHelper extends AbstractTagBasedViewHelper
@@ -36,34 +37,24 @@ public function initializeArguments(): void
public function render(): string
{
- $rssFormat = (bool)$this->arguments['rss'];
/** @var Author $author */
$author = $this->arguments['author'];
+ $rssFormat = (bool)$this->arguments['rss'];
- if ((int)$author->getDetailsPage() > 0) {
+ if ((int)$author->getDetailsPage() > 0 && !$rssFormat) {
return $this->buildUriFromDetailsPage($author, $rssFormat);
}
return $this->buildUriFromDefaultPage($author, $rssFormat);
}
- /**
- * @param Author $author
- * @param bool $rssFormat
- * @return mixed|string
- */
- protected function buildUriFromDetailsPage(Author $author, bool $rssFormat)
+ protected function buildUriFromDetailsPage(Author $author, bool $rssFormat): string
{
- $uriBuilder = $this->getUriBuilder($author->getDetailsPage(), [], $rssFormat);
+ $uriBuilder = $this->getUriBuilder((int) $author->getDetailsPage(), [], $rssFormat);
return $this->buildAnchorTag($uriBuilder->build(), $author);
}
- /**
- * @param Author $author
- * @param bool $rssFormat
- * @return mixed|string
- */
- protected function buildUriFromDefaultPage(Author $author, bool $rssFormat)
+ protected function buildUriFromDefaultPage(Author $author, bool $rssFormat): string
{
$uriBuilder = $this->getUriBuilder((int)$this->getTypoScriptFrontendController()->tmpl->setup['plugin.']['tx_blog.']['settings.']['authorUid'], [], $rssFormat);
$arguments = [
@@ -72,15 +63,8 @@ protected function buildUriFromDefaultPage(Author $author, bool $rssFormat)
return $this->buildAnchorTag($uriBuilder->uriFor('listPostsByAuthor', $arguments, 'Post', 'Blog', 'AuthorPosts'), $author);
}
- /**
- * @param int $pageUid
- * @param array $additionalParams
- * @param bool $rssFormat
- * @return UriBuilder
- */
protected function getUriBuilder(int $pageUid, array $additionalParams, bool $rssFormat): UriBuilder
{
- /** @var UriBuilder $uriBuilder */
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
$uriBuilder->reset()
->setRequest($this->renderingContext->getRequest())
@@ -94,12 +78,7 @@ protected function getUriBuilder(int $pageUid, array $additionalParams, bool $rs
return $uriBuilder;
}
- /**
- * @param string $uri
- * @param Author $author
- * @return mixed|string
- */
- protected function buildAnchorTag(string $uri, Author $author)
+ protected function buildAnchorTag(string $uri, Author $author): string
{
if ($uri !== '') {
$linkText = $this->renderChildren() ?? $author->getName();
@@ -111,10 +90,7 @@ protected function buildAnchorTag(string $uri, Author $author)
return $this->renderChildren();
}
- /**
- * @return mixed|\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
- */
- protected function getTypoScriptFrontendController()
+ protected function getTypoScriptFrontendController(): TypoScriptFrontendController
{
return $GLOBALS['TSFE'];
}
diff --git a/Tests/Functional/ViewHelpers/Link/AuthorViewHelperTest.php b/Tests/Functional/ViewHelpers/Link/AuthorViewHelperTest.php
index ede3b5a3..a526e1e7 100644
--- a/Tests/Functional/ViewHelpers/Link/AuthorViewHelperTest.php
+++ b/Tests/Functional/ViewHelpers/Link/AuthorViewHelperTest.php
@@ -24,7 +24,7 @@ public function render(string $template, string $expected): void
{
$this->createTestSite();
- (new ConnectionPool())->getConnectionForTable('pages')->insert(
+ (new ConnectionPool())->getConnectionForTable('tx_blog_domain_model_author')->insert(
'tx_blog_domain_model_author',
[
'uid' => 100,
@@ -77,4 +77,78 @@ public static function renderDataProvider(): array
],
];
}
+
+ /**
+ * @test
+ * @dataProvider renderDetailPageDataProvider
+ */
+ public function renderDetailPage(string $template, string $expected): void
+ {
+ $this->createTestSite();
+
+ (new ConnectionPool())->getConnectionForTable('pages')->insert(
+ 'pages',
+ [
+ 'uid' => 100,
+ 'pid' => 1,
+ 'doktype' => 1,
+ 'title' => 'Detail Page TYPO3 Inc Team',
+ 'slug' => '/detail-typo3-inc-team'
+ ]
+ );
+
+ (new ConnectionPool())->getConnectionForTable('tx_blog_domain_model_author')->insert(
+ 'tx_blog_domain_model_author',
+ [
+ 'uid' => 100,
+ 'pid' => self::STORAGE_UID,
+ 'name' => 'TYPO3 Inc Team',
+ 'slug' => 'typo3-inc-team',
+ 'details_page' => 100,
+ ]
+ );
+
+ $instructions = [
+ [
+ 'type' => 'author',
+ 'uid' => 100,
+ 'as' => 'author',
+ ]
+ ];
+
+ self::assertSame(
+ $expected,
+ $this->renderFluidTemplateInTestSite($template, $instructions)
+ );
+ }
+
+ public static function renderDetailPageDataProvider(): array
+ {
+ return [
+ 'simple' => [
+ '',
+ 'TYPO3 Inc Team',
+ ],
+ 'target' => [
+ '',
+ 'TYPO3 Inc Team',
+ ],
+ 'rel' => [
+ '',
+ 'TYPO3 Inc Team',
+ ],
+ 'rss' => [
+ '',
+ 'TYPO3 Inc Team',
+ ],
+ 'content' => [
+ 'Hello',
+ 'Hello',
+ ],
+ 'class' => [
+ '',
+ 'TYPO3 Inc Team',
+ ],
+ ];
+ }
}