Skip to content

Commit

Permalink
[BUGFIX] Add alternative record lookup in v:content.info
Browse files Browse the repository at this point in the history
Close: #1799
  • Loading branch information
NamelessCoder committed Jul 22, 2023
1 parent 0c43649 commit 0fd7747
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
22 changes: 21 additions & 1 deletion Classes/ViewHelpers/Content/InfoViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;

/**
* ViewHelper to access data of the current content element record.
Expand Down Expand Up @@ -72,7 +74,25 @@ public function render()
if (0 === $contentUid) {
/** @var ContentObjectRenderer $cObj */
$cObj = $this->configurationManager->getContentObject();
$record = $cObj->data;
if ($cObj->getCurrentTable() !== 'tt_content') {
throw new Exception(
'v:content.info must have contentUid argument outside tt_content context',
1690035521
);
}
if (!empty($cObj->data)) {
$record = $cObj->data;
} else {
$tsfe = $cObj->getTypoScriptFrontendController();

Check failure on line 86 in Classes/ViewHelpers/Content/InfoViewHelper.php

View workflow job for this annotation

GitHub Actions / PHPStan, PHP 7.4 TYPO3 ^10.4

Call to protected method getTypoScriptFrontendController() of class TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer.
if (!$tsfe instanceof TypoScriptFrontendController) {
throw new Exception(
'v:content.info must have contentUid argument when no TypoScriptFrontendController exists',
1690035521
);
}
$recordReference = $tsfe->currentRecord;
$contentUid = (int) substr($recordReference, strpos($recordReference, ':') + 1);
}
}

/** @var string $field */
Expand Down
25 changes: 24 additions & 1 deletion Tests/Unit/ViewHelpers/Content/InfoViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTest;
use FluidTYPO3\Vhs\Tests\Unit\ViewHelpers\AbstractViewHelperTestCase;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;

/**
* Class InfoViewHelperTest
Expand All @@ -18,6 +20,27 @@ class InfoViewHelperTest extends AbstractViewHelperTestCase
{
public function testRender()
{
$this->assertEmpty($this->executeViewHelper());
$record = ['uid' => 1];

$contentObject = $this->getMockBuilder(ContentObjectRenderer::class)
->onlyMethods(['getCurrentTable'])
->disableOriginalConstructor()
->getMock();
$contentObject->data = $record;
$contentObject->method('getCurrentTable')->willReturn('tt_content');

$configurationManager = $this->getMockBuilder(ConfigurationManagerInterface::class)
->onlyMethods(['getContentObject'])
->disableOriginalConstructor()
->getMockForAbstractClass();
$configurationManager->method('getContentObject')->willReturn($contentObject);

$instance = $this->createInstance();
$arguments = $this->buildViewHelperArguments($instance, []);
$instance->setArguments($arguments);
$instance->injectConfigurationManager($configurationManager);

$output = $instance->render();
self::assertSame($record, $output);
}
}

0 comments on commit 0fd7747

Please sign in to comment.