Development

HowToUseFCKeditor: fckFormWidget.php

You must first sign up to be able to contribute.

HowToUseFCKeditor: fckFormWidget.php

File fckFormWidget.php, 1.6 kB (added by PoWl, 9 years ago)

To be able to work with the FCK-editor as widget of a sfForm, I created this fckFormWidget

Line 
1 <?
2 /**
3     * FCK Form widget
4     *
5     * @package    ***
6     * @subpackage lib
7     * @author     $LastChangedBy: PoWl $
8     * @version    SVN: $Id: fckFormWidget.php 81 2008-12-08 00:39:59Z PoWl $
9     */
10
11 class fckFormWidget extends sfWidgetFormTextarea
12 {
13     /**
14         * @param array $options     An array of options
15         * @param array $attributes  An array of default HTML attributes
16         *
17         * @see sfWidgetForm
18         */
19     protected function configure ($options = array(), $attributes = array())
20     {
21         $this->addOption ('editor', 'fck');
22         $this->addOption ('css', false);
23
24         parent::configure ($options, $attributes);
25     }
26
27     /**
28         * @param  string $name        The element name
29         * @param  string $value       The value displayed in this widget
30         * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
31         * @param  array  $errors      An array of errors for the field
32         *
33         * @return string An HTML tag string
34         *
35         * @see sfWidgetForm
36         */
37     public function render ($name, $value = null, $attributes = array(), $errors = array())
38     {
39         $editorClass = 'sfRichTextEditorFCK';
40         if (!class_exists ($editorClass)) {
41             throw new sfConfigurationException (sprintf ('The rich text editor "%s" does not exist.', $editorClass));
42         }
43
44         $editor = new $editorClass ();
45         if (!in_array ('sfRichTextEditor', class_parents ($editor))) {
46             throw new sfConfigurationException (sprintf ('The editor "%s" must extend sfRichTextEditor.', $editor));
47         }
48
49         $attributes = array_merge ($attributes, $this->getOptions ());
50         $editor->initialize ($name, $value, $attributes);
51         return $editor->toHTML ();
52     }
53 }
54 ?>