Customizing a block - Adding a Rich Text Editor
Permalink
I'm trying to tweak a block to convert a text field to a rich text area.
The original block has a description field, but it's a regular text field. I would like to convert it to a rich text area.
I've added:
to the top of my block.
And I've replaced the original text field code:
with:
This gives me the rich text editor when I edit the block. But when I make changes to the content in the editor field, it does not update the database.
Does anyone know what I might be missing?
Thanks.
The original block has a description field, but it's a regular text field. I would like to convert it to a rich text area.
I've added:
Loader::element('editor_controls');
to the top of my block.
And I've replaced the original text field code:
<input type="text" value="<?php echo $imgInfo['Description']; ?>" name="Description[]" id="Description" style="width:100%;">
with:
<?php Loader::element('editor_controls'); ?> <textarea id="Description" name="Description[]" class="ccm-advanced-editor"><?php echo $imgInfo['Description']; ?>
This gives me the rich text editor when I edit the block. But when I make changes to the content in the editor field, it does not update the database.
Does anyone know what I might be missing?
Thanks.
Hi, you need to add as follows:
Thanks for the reply. I've added
but I get the same issue. The editor shows the existing content in the field, but if I edit it, it ignores my changes.
Loader::element('editor_config');
but I get the same issue. The editor shows the existing content in the field, but if I edit it, it ignores my changes.
you need to add the following function in your controller.
you need to replace your controller name instead of "[BLOckcontrollerClassName]" in my code.
you also need to add the following code in view function
you also need to add the following code in save function
you also need to add the following code in edit function
sometimes you may need to change property name:Description based on your block.
function translateFromEditMode($text) { // now we add in support for the links $text = preg_replace( '/{CCM:CID_([0-9]+)}/i', BASE_URL . DIR_REL . '/' . DISPATCHER_FILENAME . '?cID=\\1', $text); // now we add in support for the files $text = preg_replace_callback( '/{CCM:FID_([0-9]+)}/i', array('[BLOckcontrollerClassName]', 'replaceFileIDInEditMode'), $text); $text = preg_replace_callback( '/{CCM:FID_DL_([0-9]+)}/i', array('[BLOckcontrollerClassName]', 'replaceDownloadFileIDInEditMode'), $text);
Viewing 15 lines of 129 lines. View entire code block.
you need to replace your controller name instead of "[BLOckcontrollerClassName]" in my code.
you also need to add the following code in view function
$imginfo['Description']=$this->translateFrom($this->Description);
you also need to add the following code in save function
$args['Description'] = $this->translateTo($args['Description']);
you also need to add the following code in edit function
$args['Description'] = $this->translateFromEditMode($this->Description);
sometimes you may need to change property name:Description based on your block.
Thanks again. Definitely getting there...
I'm now getting an error for each of the $text references. Example:
Any idea what might cause that?
I'm now getting an error for each of the $text references. Example:
Warning: preg_replace_callback() [function.preg-replace-callback]: Requires argument 2, '[MyBlockController]::replaceCollectionID', to be a valid callback in (path to controller file)
Any idea what might cause that?
Please remove square bracket.
Thanks. Silly late-night mistake!
So I think the problem now is simply that the textarea contents aren't saving. The block I'm modifying doesn't actually have a public function save() command. It does have:
I have a feeling some variation of the
line needs to go in here somewhere, but I'm not hitting on something that's working.
So I think the problem now is simply that the textarea contents aren't saving. The block I'm modifying doesn't actually have a public function save() command. It does have:
function save($data) { $db = Loader::db(); $args['thumbWidth'] = isset($data['thumbWidth']) ? intval($data['thumbWidth']) : 150; $args['thumbHeight'] = isset($data['thumbHeight']) ? intval($data['thumbHeight']) : 100; if( count($data['imgFIDs']) ){ $args['fsID'] = 0; //delete existing images $db->query("DELETE FROM tableName WHERE bID=".intval($this->bID)); //loop through and add the images $pos=0; foreach($data['imgFIDs'] as $imgFID){ if(intval($imgFID)==0 || $data['fileNames'][$pos]=='tempFilename') continue; $vals = array( intval($this->bID), intval($imgFID),
Viewing 15 lines of 25 lines. View entire code block.
I have a feeling some variation of the
$args['Description'] = $this->translateTo($args['Description']);
line needs to go in here somewhere, but I'm not hitting on something that's working.