Zend Form & TinyMCE

first we create an additional view helper called formTinyMce. This will be the helper that will actually build our element. Those familiar with the framework wil recognise this as a modified version of the text area helper.

tinyMce = $this->view->tinyMce();
        $this->tinyMce->enable();
        return $this;
    }

	public function formTinyMce($name, $value = null, $attribs = null, $options = null)
	{
       $info = $this->_getInfo($name, $value, $attribs);
        extract($info); // name, value, attribs, options, listsep, disable
        // is it disabled?
        $disabled = '';
        if ($disable) {
            // disabled.
            $disabled = ' disabled="disabled"';
        }

        // Make sure that there are 'rows' and 'cols' values
        // as required by the spec.  noted by Orjan Persson.
        if (empty($attribs['rows'])) {
            $attribs['rows'] = (int) $this->rows;
        }
        if (empty($attribs['cols'])) {
            $attribs['cols'] = (int) $this->cols;
        }

        if (isset($attribs['editorOptions'])) {
        	$attribs['editorOptions']['mode'] = 'textareas';
        	if (!isset($attribs['editorOptions']['theme'])) $attribs['editorOptions']['theme'] = "simple";
        	$this->tinyMce->setEditorOptions($attribs['editorOptions']);
        	if (!isset($attribs['class'])) {
        		$attribs['class'] =  $attribs['editorOptions']['editor_selector'];
        	} else {
        		$attribs['class'] .= ' ' . $attribs['editorOptions']['editor_selector'];
        	}
        	unset($attribs['editorOptions']);
        }
        if (!isset($attribs['class'])) {
        	$attribs['class'] =  'tinyMceEditor' ;
        }
       // build the element
        $xhtml = '';

        return $xhtml;
	}
}

Now that we have the view helper in place we can now create a form element very very easily.

All you need to do is create your element file which will extend the existing Zend_Form_Element_Textarea and specify the newly created helper.

class MyLibrary_Form_Element_TinyMce extends Zend_Form_Element_Textarea
{
    /**
     * Use formTextarea view helper by default
     * @var string
     */
    public $helper = 'formTinyMce';
}

Now you just need to register your library in your form object and call the new element types. The whole thing will also allow you to use the element with a Zend_Config object too. I tend to use Ini files

form.elements.body.type = "tinyMce"
form.elements.body.options.cols = 60
form.elements.body.options.rows = 20
form.elements.body.options.label = "Content"
form.elements.body.options.description = "The main content of the page."
form.elements.body.options.editorOptions.theme = "advanced"
form.elements.body.options.editorOptions.editor_selector = "body"
form.elements.body.options.editorOptions.theme_advanced_buttons1 = "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect,|,template"
form.elements.body.options.editorOptions.theme_advanced_buttons2 = "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor"
form.elements.body.options.editorOptions.theme_advanced_buttons3 = "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|ltr,rtl,|,fullscreen"
form.elements.body.options.editorOptions.theme_advanced_buttons4 = "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage"
form.elements.body.options.editorOptions.theme_advanced_toolbar_location =  "top"
form.elements.body.options.editorOptions.theme_advanced_toolbar_align = "left"
form.elements.body.options.editorOptions.theme_advanced_statusbar_location = "bottom"
form.elements.body.options.editorOptions.theme_advanced_resizing = true
form.elements.body.options.editorOptions.content_css = "/styles/content.templates.css"
form.elements.body.options.editorOptions.imagemanager_rootpath = "content=" SITE_PATH "/images/content/"
form.elements.body.options.editorOptions.imagemanager_remember_last_path = false
form.elements.body.options.editorOptions.filemanager_rootpath = "content=" SITE_PATH "/files/content/"
form.elements.body.options.editorOptions.filemanager_remember_last_path = false

Hope this manages to help some people spped up integrating TinyMce