Open lucmuller opened 1 year ago
Right now I've achieved to solve my problem with a custom viewhelper
declare(strict_types=1);
namespace Ameos\EsieeSitepackage\ViewHelpers\Format;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Html\HtmlParser;
use Quellenform\Iconpack\Html\IconpackHtmlParser;
use TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlViewHelper as TYPO3HtmlViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
class HtmlViewHelper extends TYPO3HtmlViewHelper
{
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
*
* @return string the parsed string.
*/
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
$htmlParser = GeneralUtility::makeInstance(HtmlParser::class);
$sContent = parent::renderStatic($arguments, $renderChildrenClosure, $renderingContext);
return sprintf(
'<div class="cke_editable">%s</div>',
GeneralUtility::makeInstance(IconpackHtmlParser::class)->transformRte(html_entity_decode($sContent), $htmlParser)
);
}
}
Yes, the output must be processed by the DataProcessor at the end.
Otherwise, the content would be displayed exactly as it is stored in the database:
<icon data-iconfig="fa6:solida,circle-info"></icon>
In principle, there are many ways to solve this, and a custom ViewHelper is also possible.
Here is an example for you:
--
-- Table structure for table 'tt_content'
--
CREATE TABLE tt_content (
icontest mediumtext,
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tt_content',
[
'customfield' => [
'label' => 'My custom field',
'config' => [
'type' => 'text',
'cols' => 80,
'rows' => 15,
'enableRichtext' => true,
'richtextConfiguration' => 'default',
],
]
]
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addToAllTCAtypes(
'tt_content',
'customfield'
);
<f:format.html>{data.customfield}</f:format.html>
lib.contentElement {
templateRootPaths {
20 = EXT:mycustomextension/Resources/Private/Templates/ContentElements/
}
dataProcessing {
3212170002 = Quellenform\Iconpack\DataProcessing\IconpackProcessor
3212170002 {
fieldName = customfield
fieldType = rte
}
}
}
Note that fieldType has the value "rte"!
I don't know exactly what your extension is like, but the way shown here works and has been tested by me.
PS: Don't forget to include the TypoScript delivered with the extension, or to take over the parts that are relevant for you!
Important: I wouldn't use the function
transformRte
orIconpackHtmlParser
directly if I were you! This will probably have to be removed in the coming update (v12 compatibility)!If you really want to use your own ViewHelper, then look at the existing ViewHelper and replace the value native with rte.
This is not what I need, as I do not have a proper field in the database. I'm using a flux content element. So the rte content is stored in the pi_flexform field of the content element. RTE content is parsed through f:format.html (by the way a custom on at the moment) viewhelper and icon should be parsed when using the viewhelper (who uses lib.parseFunc_RTE)
Any News on this topic ?
What I would need is a viewhelper that would be able to process the RTE content after it has been parsed by
Sorry for the inconvenience...
Didn't remember I'v build my own viewhelper.
Here it is
<?php
declare(strict_types=1);
namespace Ameos\Package\ViewHelpers\Format;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Html\HtmlParser;
use Quellenform\Iconpack\Html\IconpackHtmlParser;
use TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlViewHelper as TYPO3HtmlViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
class HtmlViewHelper extends TYPO3HtmlViewHelper
{
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
*
* @return string the parsed string.
*/
public static function renderStatic(
array $arguments,
\Closure $renderChildrenClosure,
RenderingContextInterface $renderingContext
) {
$htmlParser = GeneralUtility::makeInstance(HtmlParser::class);
$sContent = parent::renderStatic($arguments, $renderChildrenClosure, $renderingContext);
return sprintf(
'<div class="cke_editable">%s</div>',
GeneralUtility::makeInstance(IconpackHtmlParser::class)
->transformRte(html_entity_decode($sContent), $htmlParser)
);
}
}
Note: IconpackHtmlParser::transformRte()
has been renamed to IconpackHtmlParser::transformIconsForOutput()
in the new version (1.0.0)!
https://github.com/quellenform/t3x-iconpack/blob/main/Classes/Html/IconpackHtmlParser.php
I've encountered a problem and don't know at the moment how to solve it. If I input an icon in the bodytext of a tt_content the icon is properly displayed. If I setup a rte in another type of content (in my case build with flux) the rte isn't processed in the same way.
I guess the problem is coming from the fact that the icons are processed in a dataprocessing of lib.contentElement instead of the lib.parseFunc_RTE See the capture below first icon is set in a tt_content bodytext the other on in a custom content element.
any help would be welcome.