Content - News Menu - Ressources Menu - Sitemap - Share your code - Code library - Reference
Formidable is part of the TYPO3 Project and is supported by Ameos
crdate : 2008/04/23
by : Luc Muller
in : Tips and Tricks
In this little Tip and Trick, we'll see how to make TinyMCE and RTE working together.
Your form is working with a Database.
Your databse contains a field named bodytext
You've place a renderlet:TINYMCE in your form
<renderlet:TINYMCE label="bodytext" name="bodytext" />
You've added a <process> to your <datahandler:DB>
As the magic stuff is going to happen in the process tag in the Datahandler:DB.
we'll need a process beforerender to display the RTE content inside TINYMCE and a process beforeinsertion to convert the TINYMCE content in RTE specific content
to display the RTE content inside tinyMCE add this beforerender process
<beforerender>
<userobj>
<php><![CDATA[
$aData = func_get_arg(1);
$sContent = $aData["bodytext"];
require_once(t3lib_extMgm::extPath('rtehtmlarea').'pi2/class.tx_rtehtmlarea_pi2.php');
if(!$this->RTEObj) $this->RTEObj = t3lib_div::makeInstance('tx_rtehtmlarea_pi2');
if($this->RTEObj->isAvailable()) {
$pageTSConfig = $GLOBALS['TSFE']->getPagesTSconfig();
$RTEsetup = $pageTSConfig['RTE.'];
$this->thisConfig = $RTEsetup['default.'];
$this->thisConfig = $this->thisConfig['FE.'];
$this->specConf['rte_transform']['parameters'] = array(
"flag" => "rte_enabled",
"mode" => "ts"
);
$dataArray = array();
$dataArray['bodytext'] = $sContent;
$sContent = $this->RTEObj->transformContent('rte',$dataArray['bodytext'], 'tt_news', 'bodytext', $dataArray, $this->specConf, $this->thisConfig, '', $this->thePidValue);
}
$aData["bodytext"] = $sContent;
return $aData;
]]></php>
</userobj>
</beforerender>
Basically this is instanciating a RTE object and converting the database rte content in TINYMCE content.
Do not forget to replace all the "bodytext" to your database field if needed
To convert your frontend tinyMCE content into BE RTE content add this beforeinsertion process
<beforeinsertion>
<userobj>
<php><![CDATA[
$aData = $this->oDataHandler->_getFormDataManaged();
$sContent = $aData["bodytext"];
require_once(t3lib_extMgm::extPath('rtehtmlarea').'pi2/class.tx_rtehtmlarea_pi2.php');
if(!$this->RTEObj) $this->RTEObj = t3lib_div::makeInstance('tx_rtehtmlarea_pi2');
if($this->RTEObj->isAvailable()) {
$pageTSConfig = $GLOBALS['TSFE']->getPagesTSconfig();
$RTEsetup = $pageTSConfig['RTE.'];
$this->thisConfig = $RTEsetup['default.'];
$this->thisConfig = $this->thisConfig['FE.'];
$this->specConf['rte_transform']['parameters'] = array(
"flag" => "rte_enabled",
"mode" => "ts"
);
$dataArray = array();
$dataArray['bodytext'] = $sContent;
$sContent = $this->RTEObj->transformContent('db',$dataArray['bodytext'], 'tt_news', 'bodytext', $dataArray, $this->specConf, $this->thisConfig, '', $this->thePidValue);
}
$aData["bodytext"] = $sContent;
if($this->oDataHandler->_edition() === FALSE) {
$this->bDoCreationStuff = TRUE;
}
return $aData;
]]></php>
</userobj>
</beforeinsertion>
As in the first process, we instantiate a RTE object and convert the data. But in this case, data are converted from TinyMCE to RTE just before being inserted in the database.
Remember, that because you're impacting directly the database, you have to check if you're editing or creating stuffs.
I hope that this little tip, will help you manage your application that are using RTE and should be working either in the frontend and the backend