Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to have the custom RTEs processed for icons ? #1

Open
lucmuller opened this issue Jan 20, 2023 · 6 comments
Open

How to have the custom RTEs processed for icons ? #1

lucmuller opened this issue Jan 20, 2023 · 6 comments
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers

Comments

@lucmuller
Copy link

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.

image

any help would be welcome.

@lucmuller
Copy link
Author

lucmuller commented Jan 20, 2023

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)
        );
    }
}

@stephankellermayr
Copy link
Member

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:

  1. Create a database field in ext_tables.sql:
--
-- Table structure for table 'tt_content'
--
CREATE TABLE tt_content (
    icontest mediumtext,
);
  1. Add the field in the backend by inserting the following content (or similar) in Configuration/TCA/Overrides/tt_content.php:
\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'
);
  1. Add the field to the template so that it is also displayed in the frontend:
<f:format.html>{data.customfield}</f:format.html>
  1. In order to finally process the custom field, the template must be loaded and the DataProcessor for the field must be activated:
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 or IconpackHtmlParser 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.

@stephankellermayr stephankellermayr added the good first issue Good for newcomers label Jan 20, 2023
@lucmuller
Copy link
Author

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)

@lucmuller
Copy link
Author

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 <f:format.html>
Any help on this ?

@lucmuller
Copy link
Author

lucmuller commented Apr 21, 2023

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)
        );
    }
}

@stephankellermayr stephankellermayr added the documentation Improvements or additions to documentation label Jun 28, 2023
@stephankellermayr
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants