Skip to content

Commit

Permalink
[FEATURE] Add richtextConfiguration option on Text fields
Browse files Browse the repository at this point in the history
Enables switching the CKEditor configuration based on the current field.

If empty, the page-wide RTE preset from PageTSconfig is used:

    RTE.default.preset

Resolves: FluidTYPO3#1388
  • Loading branch information
cweiske authored and NamelessCoder committed Jul 31, 2017
1 parent ed4bc00 commit 00100ee
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 8 deletions.
64 changes: 57 additions & 7 deletions Classes/Form/Field/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Flux\Configuration\BackendConfigurationManager;
use FluidTYPO3\Flux\Form;
use FluidTYPO3\Flux\Form\FieldInterface;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;

/**
* Text
*/
class Text extends Input implements FieldInterface
{

/**
* @var integer
*/
Expand All @@ -37,6 +40,11 @@ class Text extends Input implements FieldInterface
*/
protected $enableRichText = false;

/**
* @var string
*/
protected $richtextConfiguration;

/**
* @var string
*/
Expand All @@ -56,12 +64,9 @@ public function buildConfiguration()
$configuration['rows'] = $this->getRows();
$configuration['cols'] = $this->getColumns();
$configuration['eval'] = $this->getValidate();
$defaultExtras = $this->getDefaultExtras();
if (true === $this->getEnableRichText() && true === empty($defaultExtras)) {
$typoScript = $this->getConfigurationService()->getAllTypoScript();
$configuration['defaultExtras'] = $typoScript['plugin']['tx_flux']['settings']['flexform']['rteDefaults'];
} else {
$configuration['defaultExtras'] = $defaultExtras;
if (true === $this->getEnableRichText()) {
$configuration['enableRichtext'] = true;
$configuration['richtextConfiguration'] = $this->getRichtextConfiguration();
}
$renderType = $this->getRenderType();
if (false === empty($renderType)) {
Expand Down Expand Up @@ -176,4 +181,49 @@ public function setFormat($format)
{
$this->format = $format;
}

/**
* Fetch richtext editor configuration preset
*
* The following places are looked at:
*
* 1. 'richtextConfiguration' attribute of the current tag
* 2. PageTSconfig: "RTE.tx_flux.preset"
* 3. PageTSconfig: "RTE.default.preset"
*
* @return string
*/
public function getRichtextConfiguration()
{
return $this->richtextConfiguration ?: $this->getPageTsConfigForRichTextEditor();
}

/**
* @return string
*/
protected function getPageTsConfigForRichTextEditor()
{
$configurationManager = $this->getObjectManager()->get(ConfigurationManagerInterface::class);
if ($configurationManager instanceof BackendConfigurationManager) {
$pageUid = $configurationManager->getCurrentPageId();
} else {
$root = $this->getRoot();
$pageUid = $root instanceof Form ? $root->getOption('record')['pid'] ?? 0 : 0;
}

if ($pageUid) {
return BackendUtility::getPagesTSconfig($pageUid)['RTE.']['default.']['preset'] ?? 'default';
}
return 'default';
}

/**
* @param string $richtextConfiguration
* @return Text
*/
public function setRichtextConfiguration($richtextConfiguration)
{
$this->richtextConfiguration = $richtextConfiguration;
return $this;
}
}
12 changes: 11 additions & 1 deletion Classes/ViewHelpers/Field/TextViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function initializeArguments()
$this->registerArgument(
'enableRichText',
'boolean',
'Shortcut for adding value of TS plugin.tx_flux.settings.flexform.rteDefaults to "defaultExtras"',
'Enable the richtext editor (RTE)',
false,
false
);
Expand All @@ -66,6 +66,15 @@ public function initializeArguments()
false,
''
);
$this->registerArgument(
'richtextConfiguration',
'string',
'Specifies which configuration to use in combination with EXT:rte_ckeditor.' .
'If none is given, PageTSconfig "RTE.tx_flux.preset" and "RTE.default.preset" are used.' .
'More information: https://docs.typo3.org/typo3cms/TCAReference/ColumnsConfig/Properties/TextRichtextConfiugration.html',
false,
null
);
}

/**
Expand All @@ -84,6 +93,7 @@ public static function getComponent(RenderingContextInterface $renderingContext,
$text->setColumns($arguments['cols']);
$text->setRows($arguments['rows']);
$text->setEnableRichText($arguments['enableRichText']);
$text->setRichtextConfiguration($arguments['richtextConfiguration']);
$text->setRenderType($arguments['renderType']);
$text->setFormat($arguments['format']);
return $text;
Expand Down

0 comments on commit 00100ee

Please sign in to comment.