diff --git a/typo3/sysext/backend/Classes/Form/FormDataProvider/TcaText.php b/typo3/sysext/backend/Classes/Form/FormDataProvider/TcaText.php index bd38598f5df3f53090fb8b94303877835388c0ff..c296e339a9f9524cde06d42f5529be7b2bdef3e2 100644 --- a/typo3/sysext/backend/Classes/Form/FormDataProvider/TcaText.php +++ b/typo3/sysext/backend/Classes/Form/FormDataProvider/TcaText.php @@ -18,6 +18,7 @@ declare(strict_types=1); namespace TYPO3\CMS\Backend\Form\FormDataProvider; use TYPO3\CMS\Backend\Form\FormDataProviderInterface; +use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; use TYPO3\CMS\Core\Configuration\Richtext; use TYPO3\CMS\Core\Html\RteHtmlParser; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -41,7 +42,8 @@ class TcaText implements FormDataProviderInterface continue; } - if (isset($fieldConfig['config']['enableRichtext']) && (bool)$fieldConfig['config']['enableRichtext'] === true) { + // Check if richtext is enabled for the field and the user did not disable RTE in general + if (($fieldConfig['config']['enableRichtext'] ?? false) && $this->getBackendUser()->isRTE()) { $richtextConfigurationProvider = GeneralUtility::makeInstance(Richtext::class); $richtextConfiguration = $richtextConfigurationProvider->getConfiguration( $result['tableName'], @@ -50,20 +52,27 @@ class TcaText implements FormDataProviderInterface (string)$result['recordTypeValue'], $fieldConfig['config'] ); - // remember RTE preset name - $result['processedTca']['columns'][$fieldName]['config']['richtextConfigurationName'] = $fieldConfig['config']['richtextConfiguration'] ?? ''; - // Add final resolved configuration to TCA array - $result['processedTca']['columns'][$fieldName]['config']['richtextConfiguration'] = $richtextConfiguration; - - // If eval=null is set for field, value might be null ... don't transform anything in this case. - if ($result['databaseRow'][$fieldName] !== null) { - // Process "from-db-to-rte" on current value - $richTextParser = GeneralUtility::makeInstance(RteHtmlParser::class); - $result['databaseRow'][$fieldName] = $richTextParser->transformTextForRichTextEditor($result['databaseRow'][$fieldName], $richtextConfiguration['proc.'] ?? []); + // Transform if richtext is not disabled in configuration + if (!($richtextConfiguration['disabled'] ?? false)) { + // remember RTE preset name + $result['processedTca']['columns'][$fieldName]['config']['richtextConfigurationName'] = $fieldConfig['config']['richtextConfiguration'] ?? ''; + // Add final resolved configuration to TCA array + $result['processedTca']['columns'][$fieldName]['config']['richtextConfiguration'] = $richtextConfiguration; + // If eval=null is set for field, value might be null ... don't transform anything in this case. + if ($result['databaseRow'][$fieldName] !== null) { + // Process "from-db-to-rte" on current value + $richTextParser = GeneralUtility::makeInstance(RteHtmlParser::class); + $result['databaseRow'][$fieldName] = $richTextParser->transformTextForRichTextEditor($result['databaseRow'][$fieldName], $richtextConfiguration['proc.'] ?? []); + } } } } return $result; } + + protected function getBackendUser(): BackendUserAuthentication + { + return $GLOBALS['BE_USER']; + } } diff --git a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaTextTest.php b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaTextTest.php index 73b55116e44b3c2285e8756f77f5fd7339d75b93..1ae930ae7285014a4d9274c93545a0e877c38e23 100644 --- a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaTextTest.php +++ b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaTextTest.php @@ -17,7 +17,9 @@ declare(strict_types=1); namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider; +use Prophecy\PhpUnit\ProphecyTrait; use TYPO3\CMS\Backend\Form\FormDataProvider\TcaText; +use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; use TYPO3\CMS\Core\Configuration\Richtext; use TYPO3\CMS\Core\Html\RteHtmlParser; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -28,12 +30,17 @@ use TYPO3\TestingFramework\Core\Unit\UnitTestCase; */ class TcaTextTest extends UnitTestCase { - use \Prophecy\PhpUnit\ProphecyTrait; + use ProphecyTrait; + /** * @test */ - public function addDataSetsRichtextConfigurationAndTransformsContent() + public function addDataSetsRichtextConfigurationAndTransformsContent(): void { + $beUserProphecy = $this->prophesize(BackendUserAuthentication::class); + $beUserProphecy->isRTE()->willReturn(true); + $GLOBALS['BE_USER'] = $beUserProphecy->reveal(); + $input = [ 'tableName' => 'aTable', 'effectivePid' => 42, @@ -101,4 +108,118 @@ class TcaTextTest extends UnitTestCase self::assertSame($expected, (new TcaText())->addData($input)); } + + /** + * @test + */ + public function addDataDoesNotTransformsContentWhenRichtextIsNotSet(): void + { + $beUserProphecy = $this->prophesize(BackendUserAuthentication::class); + $beUserProphecy->isRTE()->willReturn(true); + $GLOBALS['BE_USER'] = $beUserProphecy->reveal(); + + $input = [ + 'tableName' => 'aTable', + 'effectivePid' => 42, + 'recordTypeValue' => 23, + 'databaseRow' => [ + 'aField' => 'notProcessedContent', + ], + 'processedTca' => [ + 'columns' => [ + 'aField' => [ + 'config' => [ + 'type' => 'text', + ] + ], + ], + ], + ]; + + // No processing should be performed + $expected = $input; + self::assertSame($expected, (new TcaText())->addData($input)); + } + + /** + * @test + */ + public function addDataDoesNotTransformsContentWhenRichtextIsDisabledInConfiguration(): void + { + $beUserProphecy = $this->prophesize(BackendUserAuthentication::class); + $beUserProphecy->isRTE()->willReturn(true); + $GLOBALS['BE_USER'] = $beUserProphecy->reveal(); + + $input = [ + 'tableName' => 'aTable', + 'effectivePid' => 42, + 'recordTypeValue' => 23, + 'databaseRow' => [ + 'aField' => 'notProcessedContent', + ], + 'processedTca' => [ + 'columns' => [ + 'aField' => [ + 'config' => [ + 'type' => 'text', + 'enableRichtext' => true, + ], + ], + ], + ], + ]; + + $richtextConfigurationProphecy = $this->prophesize(Richtext::class); + GeneralUtility::addInstance(Richtext::class, $richtextConfigurationProphecy->reveal()); + + $richtextConfigurationProphecy + ->getConfiguration( + 'aTable', + 'aField', + 42, + 23, + [ + 'type' => 'text', + 'enableRichtext' => true, + ] + ) + ->willReturn(['disabled' => '1']); + + // No processing should be performed + $expected = $input; + self::assertSame($expected, (new TcaText())->addData($input)); + } + + /** + * @test + */ + public function addDataDoesNotTransformsContentWhenRichtextIsDisabledForUser(): void + { + $beUserProphecy = $this->prophesize(BackendUserAuthentication::class); + $beUserProphecy->isRTE()->willReturn(false); + $GLOBALS['BE_USER'] = $beUserProphecy->reveal(); + + $input = [ + 'tableName' => 'aTable', + 'effectivePid' => 42, + 'recordTypeValue' => 23, + 'databaseRow' => [ + 'aField' => 'notProcessedContent', + ], + 'processedTca' => [ + 'columns' => [ + 'aField' => [ + 'config' => [ + 'type' => 'text', + 'enableRichtext' => true, + ], + ], + ], + ], + ]; + + // No processing should be performed + $expected = $input; + self::assertSame($expected, (new TcaText())->addData($input)); + } } diff --git a/typo3/sysext/core/Classes/Authentication/BackendUserAuthentication.php b/typo3/sysext/core/Classes/Authentication/BackendUserAuthentication.php index 2323713841767b4cc8b49ca6ed8ec80f0a177640..da119f2e40c3a654e20865a34523d4ca33d0367f 100644 --- a/typo3/sysext/core/Classes/Authentication/BackendUserAuthentication.php +++ b/typo3/sysext/core/Classes/Authentication/BackendUserAuthentication.php @@ -586,9 +586,9 @@ class BackendUserAuthentication extends AbstractUserAuthentication * @return bool * @internal should only be used from within TYPO3 Core */ - public function isRTE() + public function isRTE(): bool { - return (bool)$this->uc['edit_RTE']; + return (bool)($this->uc['edit_RTE'] ?? false); } /**