Skip to content

Commit

Permalink
[BUGFIX] Set request in renderingContext of FluidRenderer
Browse files Browse the repository at this point in the history
This allows usage of link view helpers which require the request object.

Resolves: #568
Release: 12.0.1
  • Loading branch information
opi99 committed Apr 29, 2024
1 parent ad61a6e commit 8da0f5f
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
17 changes: 9 additions & 8 deletions Classes/Controller/Frontend/FrontendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Tvp\TemplaVoilaPlus\Controller\Frontend;

use Psr\Http\Message\ServerRequestInterface;
use Tvp\TemplaVoilaPlus\Configuration\FlexForm\FlexFormTools8;
use Tvp\TemplaVoilaPlus\Domain\Model\Configuration\DataConfiguration;
use Tvp\TemplaVoilaPlus\Domain\Model\Configuration\MappingConfiguration;
Expand Down Expand Up @@ -57,7 +58,7 @@ public function __construct()
* page.10.userFunc = Tvp\TemplaVoilaPlus\Controller\Frontend\FrontendController->renderPage
*/
// phpcs:disable
public function main_page($content, $conf)
public function main_page($content, $conf, ServerRequestInterface $request)
{
// phpcs:enable
trigger_error(
Expand All @@ -66,7 +67,7 @@ public function main_page($content, $conf)
'please change to "Tvp\TemplaVoilaPlus\Controller\Frontend\FrontendController->renderPage"',
E_USER_DEPRECATED
);
return $this->renderPage($content, $conf);
return $this->renderPage($content, $conf, $request);
}

/**
Expand All @@ -78,7 +79,7 @@ public function main_page($content, $conf)
* @return string HTML content for the Flexible Content elements.
* @throws \InvalidArgumentException
*/
public function renderPage($content, $conf)
public function renderPage($content, $conf, ServerRequestInterface $request)
{
/** @var ApiService */
$apiService = GeneralUtility::makeInstance(ApiService::class, 'pages');
Expand Down Expand Up @@ -122,12 +123,12 @@ public function renderPage($content, $conf)
);
}

return $this->renderElement($pageRecord, 'pages', $conf);
return $this->renderElement($pageRecord, 'pages', $conf, $request);
}

public function renderContent($content, $conf)
public function renderContent($content, $conf, ServerRequestInterface $request)
{
return $this->renderElement($this->cObj->data, 'tt_content', $conf);
return $this->renderElement($this->cObj->data, 'tt_content', $conf, $request);
}

/**
Expand All @@ -142,7 +143,7 @@ public function renderContent($content, $conf)
* @throws \Exception
*
*/
public function renderElement($row, $table, array $conf)
public function renderElement($row, $table, array $conf, ServerRequestInterface $request)
{
try {
// pages where checked for empty map already, but not tt_content
Expand Down Expand Up @@ -206,7 +207,7 @@ public function renderElement($row, $table, array $conf)
PageBasicsHandler::processConfiguration($templateConfiguration, $this->frontendController);

// give TemplateData to renderer and return result
return $renderer->renderTemplate($templateConfiguration, $processedValues, $row);
return $renderer->renderTemplate($templateConfiguration, $processedValues, $row, $request);
} catch (\Exception $e) {
// only log if $table is tt_content and exception is for tt_content, because elso it will be logged twice
if ($e instanceof ContentElementWithoutMapException && $table == 'tt_content') {
Expand Down
4 changes: 3 additions & 1 deletion Classes/Handler/Render/FluidRenderHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* The TYPO3 project - inspiring people to share!
*/

use Psr\Http\Message\ServerRequestInterface;
use Tvp\TemplaVoilaPlus\Domain\Model\Configuration\TemplateConfiguration;
use Tvp\TemplaVoilaPlus\Handler\Render\RenderHandlerInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -26,13 +27,14 @@ class FluidRenderHandler implements RenderHandlerInterface
{
public static $identifier = 'TVP\Renderer\Fluid';

public function renderTemplate(TemplateConfiguration $templateConfiguration, array $processedValues, array $row): string
public function renderTemplate(TemplateConfiguration $templateConfiguration, array $processedValues, array $row, ServerRequestInterface $request): string
{
/** @var StandaloneView */
$view = GeneralUtility::makeInstance(StandaloneView::class);
$path = GeneralUtility::getFileAbsFileName($templateConfiguration->getPlace()->getEntryPoint());
$options = $templateConfiguration->getOptions();

$view->setRequest($request);
/** @TODO Check if template file otherwise bad error messages will happen */
$view->setTemplatePathAndFilename(GeneralUtility::getFileAbsFileName($templateConfiguration->getTemplateFileName()));

Expand Down
3 changes: 2 additions & 1 deletion Classes/Handler/Render/MarkerBasedRenderHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* The TYPO3 project - inspiring people to share!
*/

use Psr\Http\Message\ServerRequestInterface;
use Tvp\TemplaVoilaPlus\Domain\Model\Configuration\TemplateConfiguration;
use TYPO3\CMS\Core\Service\MarkerBasedTemplateService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -25,7 +26,7 @@ class MarkerBasedRenderHandler implements RenderHandlerInterface
{
public static $identifier = 'TVP\Renderer\MarkerBased';

public function renderTemplate(TemplateConfiguration $templateConfiguration, array $processedValues, array $row): string
public function renderTemplate(TemplateConfiguration $templateConfiguration, array $processedValues, array $row, ServerRequestInterface $request): string
{
/** @var MarkerBasedTemplateService */
$markerBasedTemplateService = GeneralUtility::makeInstance(MarkerBasedTemplateService::class);
Expand Down
3 changes: 2 additions & 1 deletion Classes/Handler/Render/RenderHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
* The TYPO3 project - inspiring people to share!
*/

use Psr\Http\Message\ServerRequestInterface;
use Tvp\TemplaVoilaPlus\Domain\Model\Configuration\TemplateConfiguration;

interface RenderHandlerInterface
{
public function renderTemplate(TemplateConfiguration $templateConfiguration, array $processedValues, array $row): string;
public function renderTemplate(TemplateConfiguration $templateConfiguration, array $processedValues, array $row, ServerRequestInterface $request): string;
}
4 changes: 3 additions & 1 deletion Classes/Handler/Render/XpathRenderHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*
* The TYPO3 project - inspiring people to share!
*/

use Psr\Http\Message\ServerRequestInterface;
use Tvp\TemplaVoilaPlus\Domain\Model\Configuration\TemplateConfiguration;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand All @@ -28,7 +30,7 @@ class XpathRenderHandler implements RenderHandlerInterface
protected $domDocument;
protected $domXpath;

public function renderTemplate(TemplateConfiguration $templateConfiguration, array $processedValues, array $row): string
public function renderTemplate(TemplateConfiguration $templateConfiguration, array $processedValues, array $row, ServerRequestInterface $request): string
{
$this->domDocument = new \DOMDocument();
libxml_use_internal_errors(true);
Expand Down
2 changes: 1 addition & 1 deletion Classes/ViewHelpers/RenderLayoutViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ public static function renderStatic(

$backendLayoutConfiguration = ApiHelperUtility::getBackendLayoutConfiguration($combinedConfigurationIdentifier);
$renderer = $configurationService->getHandler($backendLayoutConfiguration->getRenderHandlerIdentifier());
return $renderer->renderTemplate($backendLayoutConfiguration, $variables, []);
return $renderer->renderTemplate($backendLayoutConfiguration, $variables, [], $renderingContext->getRequest());
}
}

0 comments on commit 8da0f5f

Please sign in to comment.