Monday, August 8, 2011

Integrate and customize fckeditor with symfony

Till date, I always preferred tinymce rich text editor with symfony. But noticing that it does not provide inbuilt functionality for file uploading with browse.


After getting my hands burns on with plug-ins, I than moved to remove the tinymce and go with FCKEditor. Believe me it was worth opting for the later. Though it was not an easy task to get it work with symfony 1.4 but neither it was too hard if followed the basic steps.

Below are steps which provide me with perfect integration of fckEditor.

I am assuming, you already have fckeditor symfony plug-in and fckeditor js lib in your source code.

1: Copy and paste fckeditor_php5.php
           copy from projectName/web/js/fckeditor/fckeditor_php5.php TO projectName/lib/fckeditor_php5.php
2. save fckconfig.js as customconfig.js
           copy from projectName/web/js/fckeditor/fckconfig.js TO projectName/web/js/fckeditor/customconfig.js


Basically, you would have to make all your changes to customconfig.js and no change to fckconfig.js
Though it seems typical, I tried changing directly fckconfig.js but to no avail. It did not had any changes affected. :(


In customconfig.js
 1. to change the skin theme, FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/silver/' ;
// there are 3 skins available. Default, silver and office2003
 2. To provide only required ToolbarSets, change appropriate changes to FCKConfig.ToolbarSets["Default"]
Mine is as below:

FCKConfig.ToolbarSets["Default"] = [
    ['Source','DocProps', 'Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
    ['Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript'],
    ['OrderedList','UnorderedList','-','Outdent','Indent','Blockquote','CreateDiv'],
    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull'],
    ['Link','Unlink','Anchor'],
    ['Image','Flash','Table','Rule','Smiley','SpecialChar'],
    '/',
    ['Style','FontFormat','FontName','FontSize'],
    ['TextColor','BGColor'],
    ['FitWindow','ShowBlocks','-','About']        // No comma for the last row.
] ;
3. to allow fckeditor to submit data to the form set below config to false. If its set to true than no change in data would be send to serve.
FCKConfig.MsWebBrowserControlCompat = false ;
FCKConfig.PreventSubmitHandler = false ;


Now the final change:

Since we have change the config file from fckconfig.js to customconfig.js, we need to load the same js.
To change so, open fckeditor.html at     /js/fckeditor/editor/fckeditor.html
Change LoadScript( '../fckconfig.js' )  to LoadScript( '../customconfig.js' ) ;

For Symfony changes
Get the sfFCKEditorPlugin from here
install the plugin
Enable plugin from your config/ProjectConfiguration.class.php
$this->enablePlugins('sfFCKEditorPlugin');

Make the change in settings.yml in your modules directroy
all:
  .settings:
    rich_text_fck_js_dir: js/fckeditor

In the form.class, do the following for widget you need fckeditor:
$oFCKEditor = new sfWidgetFormFCKEditor(array('rows'=>50));
$this->setWidgets(array('Text'  =>  $oFCKEditor,));

This is it. Hope it helps.

For any concerns, feel free to mail me or post comments





7 comments:

  1. How can I apply validation to FCKeditor in symfony

    ReplyDelete
  2. Hey chaitanya,

    Let me first thank you for posting your question.
    Can you tell me what validation you need to have for fckeditor?
    are you trying to say validating textarea, where fckeditor is implemented? in that case, you dont need to validate on fckeditor but its simple jquery validation for textarea id, or field name you have in the form.

    Let me know if above is your concern or something else?

    ReplyDelete
  3. Very refreshing blog and very refreshing ideas. Im glad that I came across this when I did. I love what youve got to say and the way you say it.


    aion accounts

    ReplyDelete
  4. These kinds of articles are always attractive and I am happy to find so many good points here in the post. I appreciate it very much! I am looking forward to other share. Thank you so much!


    http://isabeldelosrios.co

    ReplyDelete
  5. I visited your site & after visiting i found that it is very informational for everyone you have done really a great job



    Injury lawyer

    ReplyDelete
  6. I need to belatedly thank you……………………..




    WOW gold

    ReplyDelete
  7. I think I will become a great follower.Just want to say your article is striking. The clarity in your post is simply striking and i can take for granted you are an expert on this subject. utah seo consultant

    ReplyDelete