菜单

Using htmlArea RTE in a frontend plugin

2010年06月1日 - typo3

Extension developers may use the htmlArea RTE to edit textarea fields in frontend plugins. In order to  do so, you must invoke the htmlArea plugin in the plugin class and insert some markers in the HTML template.

Invoking the htmlArea RTE frontend plugin

Step 1. Include the htmlArea RTE frontend plugin:

require_once(t3lib_extMgm::extPath('rtehtmlarea').'pi2/class.tx_rtehtmlarea_pi2.php');

Step 2. Declare the following class variables for the RTE API:

var $RTEObj;
var $docLarge = 0;
var $RTEcounter = 0;
var $formName;
var $additionalJS_initial = '';// Initial JavaScript to be printed before the form (should be in head, but cannot due to IE6 timing bug)
var $additionalJS_pre = array();// Additional JavaScript to be printed before the form (works in Mozilla/Firefox when included in head, but not in IE6)
var $additionalJS_post = array();// Additional JavaScript to be printed after the form
var $additionalJS_submit = array();// Additional JavaScript to be executed on submit
var $PA = array(
'itemFormElName' =>  '',
'itemFormElValue' => '',
);
var $specConf = array(
'rte_transform' => array(
'parameters' => array('mode' => 'ts_css')
)
);
var $thisConfig = array();
var $RTEtypeVal = 'text';
var $thePidValue;

Step 3. Set the HTML markers for rendering the form:

$this->postvars = t3lib_div::_POST('tx_myextension_pi1');
if(!$this->RTEObj)  $this->RTEObj = t3lib_div::makeInstance('tx_rtehtmlarea_pi2');
if($this->RTEObj->isAvailable()) {
$this->RTEcounter++;
$this->table = 'my-table-name';
$this->field = 'my-field-name';
$this->formName = 'my-form-name';
$this->PA['itemFormElName'] = 'tx_myextension_pi1[my-field-name]';
$this->PA['itemFormElValue'] = $this->postvars['my-field-name'];
$this->thePidValue = $GLOBALS['TSFE']->id;
$RTEItem = $this->RTEObj->drawRTE($this, 'my-table-name', 'my-field-name', $row=array(), $this->PA, $this->specConf, $this->thisConfig, $this->RTEtypeVal, '', $this->thePidValue);
$markerArray['###ADDITIONALJS_PRE###'] = $this->additionalJS_initial.'
<script type="text/javascript">'. implode(chr(10), $this->additionalJS_pre).'
</script>';
$markerArray['###ADDITIONALJS_POST###'] = '
<script type="text/javascript">'. implode(chr(10), $this->additionalJS_post).'
</script>';
$markerArray['###ADDITIONALJS_SUBMIT###'] = implode(';', $this->additionalJS_submit);
$markerArray['###FORM_RTE_ENTRY###'] = $RTEItem;
}

Step 4. Process and save data sent in the textarea:

if($this->RTEObj->isAvailable()) {
$pageTSConfig = $GLOBALS['TSFE']->getPagesTSconfig();
$RTEsetup = $pageTSConfig['RTE.'];
$this->thisConfig = $RTEsetup['default.'];
$this->thisConfig = $this->thisConfig['FE.'];
$dataArray['my-field-name'] = $this->RTEObj->transformContent('db',$dataArray['my-field-name'], 'my-table-name', 'my-field-name', $dataArray, $this->specConf, $this->thisConfig, '', $this->thePidValue);
}
$insert = $GLOBALS['TYPO3_DB']->exec_INSERTquery('my-table-name', $dataArray);

where $dataArray is the array of data used to insert the data into the table.

Inserting markers in the HTML template

Step 1. Insert JavaScript marker before the form:

###ADDITIONALJS_PRE###

Step 2. Insert onSubmit marker on the form tag:

<form name="my-form-name" method="post" action="###ACTION_URL###" onsubmit="###ADDITIONALJS_SUBMIT###" >

Step3. Replace the <textarea> tag and its contents with:

###FORM_RTE_ENTRY###

Step4. Insert JavaScript marker after the form:

###ADDITIONALJS_POST###

Setting the style attribute of the editing area

You may use $this->RTEObj->RTEWrapStyle and $this->RTEObj->RTEdivStyle to set the style attributes of the editing area and of its wrapping div.

标签:

发表评论

电子邮件地址不会被公开。 必填项已用*标注