ew_base/Classes/ViewHelpers/FixFlexformForExtbaseViewHelper.php
2024-12-26 21:44:19 +01:00

66 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
/*
* This file is developed by evoWeb.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
namespace Evoweb\EwBase\ViewHelpers;
use TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* = Examples =
*
* <code title="Simple Loop">
* <ewb:fixFlexformForExtbase data="{data}">....</ewb:fixFlexformForExtbase>
* </code>
* <output>
* fixed flexform data for extbase controller
* </output>
*
* @api
*/
class FixFlexformForExtbaseViewHelper extends AbstractViewHelper
{
/**
* @var boolean
*/
protected $escapeOutput = false;
public function initializeArguments(): void
{
parent::initializeArguments();
$this->registerArgument('data', 'array', 'The data array of content element', true);
}
public function render(): string
{
$templateVariableContainer = $this->renderingContext->getVariableProvider();
/** @var FlexFormTools $flexFormTools */
$flexFormTools = GeneralUtility::makeInstance(FlexFormTools::class);
$data = $this->arguments['data'];
if (is_array($data['pi_flexform'])) {
$data['pi_flexform'] = $flexFormTools->flexArray2Xml($data['pi_flexform']);
}
$templateVariableContainer->add('data', $data);
$output = $this->renderChildren();
$templateVariableContainer->remove('data');
return $output;
}
}