jurian sluiman

{
Wissel naar

Improved TinyMce solution for the Zend Framework

Some time ago Matt Cockayne posted a solution to get TinyMce working as a form element inside a Zend_Form_Element. I had a look at his code and thought it was a very good one. But as critical I am, I thought there were some points still able to improve.

Because Soflomo has the open library Sozfo, it's a good idea to put this new element inside the Sozfo library isn't it? When you look at it, you see some similarities between his and mine solution:

  1. We both use a Zend_Form_Element_Textarea which point to a view helper called FormTinyMce. The element is nothing special, the view helper initiates the <textarea> element with all attributes.
  2. We both use another view helper to add the javascript required to initiate the TinyMce editor.

Of course there are some differences. When I read Matt's post about the implementation I noticed he had a lot of special configuration he personally used. For example a template system which used a content_templates class. He also forced to use the php TinyMce compressor.

Another point was the usage of a container. Matt saw the similarities between the jQuery container and a container especially for TinyMce. The container implies you have a $this->tinyMce() inside your template. When a form is loaded, the view helper "enables" itself and adds some code inside your layout.

But actually, it's not necessary to create a container. The TinyMce view helper is able to push all javascript inside the HeadScript view helper. By removing the container the code is better to read and understand I think.

The Sozfo solution

The form element is actually the same as Matt's one, but you can find it online here. The form view helper is made a little bit simpler:

public function FormTinyMce ($name, $value = null, $attribs = null)
{
    $info = $this->_getInfo($name, $value, $attribs);
    extract($info); // name, value, attribs, options, listsep, disable

    $disabled = '';
    if ($disable) {
        $disabled = ' disabled="disabled"';
    }

    if (empty($attribs['rows'])) {
        $attribs['rows'] = (int) $this->rows;
    }
    if (empty($attribs['cols'])) {
        $attribs['cols'] = (int) $this->cols;
    }

    if (isset($attribs['editorOptions'])) {
        if ($attribs['editorOptions'] instanceof Zend_Config) {
            $attribs['editorOptions'] = $attribs['editorOptions']->toArray();
        }
        $this->view->tinyMce()->setOptions($attribs['editorOptions']);
        unset($attribs['editorOptions']);
    }
    $this->view->tinyMce()->render();

    $xhtml = '<textarea name="' . $this->view->escape($name) . '"'
            . ' id="' . $this->view->escape($id) . '"'
            . $disabled
            . $this->_htmlAttribs($attribs) . '>'
            . $this->view->escape($value) . '</textarea>';

    return $xhtml;
}

One important thing to mention is tinyMce will always be enabled. Because the view helper has some defaults, the form element is working even without any configuration!
If a config is present, it's pushed to the view helper.

The TinyMce view helper is too long to post here (at Google Code it's easier to read), but the most important functions are these ones:

public function render()
{
    if (false === $this->_enabled) {
        $this->_renderScript();
        $this->_renderCompressor();
        $this->_renderEditor();
        $this->_enabled = true;
    }
}

protected function _renderScript ()
{
    if (null === $this->_scriptFile) {
        $script = $this->_defaultScript;
    } else {
        $script = $this->_scriptPath . '/' . $this->_scriptFile;
    }

    $this->view->headScript()->appendFile($script);
    return $this;
}

protected function _renderCompressor ()
{
    if (false === $this->_useCompressor) {
        return;
    }
    $script = 'tinyMCE_GZ.init({' . PHP_EOL
            . 'themes: "' . implode(',', $this->_supportedTheme) . '"' . PHP_EOL
            . 'plugins: "'. implode(',', $this->_supportedPlugins) . '"' . PHP_EOL
            . 'languages: "' . implode(',', $this->_supportedLanguages) . '"' . PHP_EOL
            . 'disk_cache: true' . PHP_EOL
            . 'debug: false' . PHP_EOL
            . '});';

    $this->view->headScript()->appendScript($script);
    return $this;
}

protected function _renderEditor ()
{
    $script = 'tinyMCE.init({' . PHP_EOL;

    foreach ($this->_config as $name => $value) {
        if (is_array($value)) {
            $value = implode(',', $value);
        }
        if (!is_bool($value)) {
            $value = '"' . $value . '"';
        }
        $script .= $name . ': ' . $value . ',' . PHP_EOL;
    }

    $script .= '});';

    $this->view->headScript()->appendScript($script);
    return $this;
}

I think it's pretty clear. The render can only be executed once and exists of three parts: the inclusion of the TinyMce script, the compressor options (if required) and the actual initialisation of the TinyMce editor.

Configuration

When you want to configure the TinyMce for, it's really easy to do with an ini file and Zend_Config_Ini. For example I have those two configurations:

[editor]
scriptPath = "/js/tiny_mce/"
scriptFile = "tiny_mce.js"
mode = "textareas"
element_format = "html"
forced_root_block = "p"

[user : editor]
theme = "simple"

[moderator : editor]
theme = "advanced"
width = "580"
height= "300"
plugins= "paste, table"
theme_advanced_resizing = true
theme_advanced_resizing_use_cookie = false
theme_advanced_toolbar_location = "top"
theme_advanced_buttons1 = "formatselect, bold, italic, underline, strikethrough, |, justifyleft, justifycenter, justifyright, justifyfull, |, bullist, numlist, |, outdent, indent, blockquote, |, undo, redo, cleanup, removeformat, pasteword, code "
theme_advanced_buttons2 = "link, unlink, anchor, |, image, hr , sub, sup, charmap, |, forecolor, backcolor, |, tablecontrols"
theme_advanced_buttons3 = ""
theme_advanced_blockformats = "p,h1,h2,h3,blockquote,dt,dd"

If you want to add some configuration for your element, just do so by the following:

$this->addElement('tinyMce', 'message', array(
    'label'      => 'Message',
    'required'   => true,
    'cols'       => '50',
    'rows'       => '10',
    'editorOptions' => new Zend_Config_Ini(APPLICATION_PATH . '/configs/tinymce.ini', 'user')
));

Download

The form element and view helpers are located in trunk of the Sozfo library. I haven't had any time to create a prefab package like a zip or something. But after my exams I'll be able to do so.

Suggestions

If you have more suggestions about this implementation, or comment to improve Matt's or my code, please let me know!

Comments

Matt Cockayne

I like the changes you made.
I see you point regarding the fact that i did include a options/plugins of TinyMce that I really should have left out (i.e. templates).

I'm not so sure of the editor always being enabled though as I like to keep the amount of JS loaded to a minimum where possible, so being able to turn it on and off was very useful for me at the time I built the component.

I have given the idea of a container a lot of consideration and am not 100% on either way of implementation. I don't think either way is right or wrong, just that it needs more investigation before I could say I prefer one over the other.

I have just been signed off as a contributor for the Zend Framework so I am hoping to put forward a proposal for a component that will allow direct integration of TinyMCE and any other suggested editors. I'll keep you posted as it develops

Jurian Sluiman

I'm still trying to understand the use of TinyMce templates better. When you want to turn off the javascript code, you can also change the element from 'tinyMce' into 'textarea'. Furthermore, I also have some improvements for my own code.

For example, when you pass an array of options (like plugins), the view will look if all items are in the supported list of plugins. This is especially useful when you try to pass an unsuported mode of theme.

PS. I know there are some problems with the reaction form. I'll try to investigate it asap :)

Matt Cockayne

The templates are a pretty useful tool when you get the hang of them. Along with the noneditable plugin it makes the editor very powerful tool for CMS style page editing.

I miss read the bit about it always being enabled (doh). It made more sense on the second read through.

Your alterations have actually prompted me to rethink a whole segment of my code in preparation for putting together a proposal to submit to the framework.

Its not a totally standalone component rather than bits I have tagged together "Zucchi_Wysiwyg". hopefully the structure I have created will also allow me to add different types of editor to the collection as I go along.

I have rebuilt to utilise the resource loader and created a resource to load all the relevant bits

I'm separateing out the more obscure plugins to alow independant configuration per editor loaded.

The compressor is now optional.

Its still VERY buggy while Im working out the kinks but what I have is available at https://subversion.zucchi.co.uk/listing.php?repname=library&path=%2Ftrunk%2FZucchi%2F#path_trunk_Zucchi_

Your thoughts would be very much appreciated.

matt.cockayne

that was meant to read

"Its now a totally standalone component rather than bits I have tagged together "Zucchi_Wysiwyg"."

Jurian Sluiman

Hi Matt,

I understand your point about facilitating a WYSIWYG editor with a unified interface for any editor. I'd be a very good idea if that\'s possible, but I have my doubts about it (sorry :p). As long as you have completely different configurations for every editor, it's difficult to provide a single interface for all those elements.

Because I have exams at the moment, I don't have the time to dig through all your code. I see it hasn't change much, but there are still some changes. Do you have actually an idea for an api for the WYSIWYG element? If some people would like to change to FCKeditor, will this be possible with your Zucchi_Wysiwyg?

PS. Sorry I don't let you post any links, that's just to prevent spamming ;)

Mougli

Hi!

I'm trying to implement TinyMce for hours, but I don't succeed. I have no idea what to do. I've checked your SVN repositroy and I have all the files you have in the same places but I'm getting an exception

Message: Plugin by name 'TinyMce' was not found in the registry; used paths: Zend_Form_Element_: Zend/Form/Element/

I guess it should search in App/Form/Form.php? I don't know. I don't understand zf jet :)

Your help will be most appreciated.

Jurian Sluiman
Hi Mougli,
You're completely right! I didn't mention it in my explanation, I'm sorry about that.
The form you create is usually a child of Zend_Form. Because I have added another form element, you should add those elements with the method Zend_Form::addPrefixPath(). If you look at the Sozfo library source, you can find the Sozfo_Form adding that prefix (http://code.google.com/p/sozfo/source/browse/trunk/library/Sozfo/Form.php).
If your forms are extending Sofzo_Form instead of Zend_Form, everything will work as expected. Thanks for pointing the missing part. I'll update it as soon as possible.
Mougli
Hi!
I'm still having problems. Now I get no error or exception, everything works fine, I just don't get tinyMce editor. I get ordinary textarea...

<dt id="longDescription-label"><label for="longDescription" class="required">Opis:label>dt>
<dd id="longDescription-element">
<textarea name="longDescription" id="longDescription" cols="40" rows="10">textarea>dd>

This is my source code for tiny...

Any idea? :)

Jurian Sluiman
I think something's going wrong with initializing the javascript. If you have Firefox, try to look into the error console for some errors. The script defaults are online at the Google code project, but that might give some errors.

I'm using always the configuration option to set the scriptPath and scriptFile locally (i.e. at the same place the application is running). You might want to download tinyMce yourself and point the form element to that location.

Mougli
Ok, I fixed that. In case someone else will have the same problem...
In function _renderScript() I changed
$this->view->headScript()->appendFile($script);
to
$this->view->headScript()->appendFile($this->view->baseUrl() . $script);

Jurian, tnx for your help :)
Paul

I am still getting the message "Warning: Plugin by name 'FormTinyMce' was not found in the registry". I have tried tweaking the bootstrap, moving the files around.

What is the trick getting Zend to find the plugin.
I am extended using Sofzo_Form with no errors.
Any help really appreciated.
Thanks
Paul

Mads

Hi

Thank for this, worked well for my implementation.

Found a small bug using it in IE7. The last line of the config it inserts produce a JS error in IE7 because it has a trailing comma.

Fixed it in the TinyMce view helper by adding a small change to the _renderEditor method to this result:

 protected function _renderEditor ()
    {
        $script = 'tinyMCE.init({' . PHP_EOL;
        $config_count = count($this->_config);
        $count = 1;
        foreach ($this->_config as $name => $value) {
            if (is_array($value)) {
                $value = implode(',', $value);
            }
            if (!is_bool($value)) {
                $value = '"' . $value . '"';
            }
            $comma = ($count <= $config_count-1) ? ',' : '';
            $script .= $name . ': ' . $value . $comma . PHP_EOL;
            $count++;
        }

        $script .= '});';

        $this->view->headScript()->appendScript($script);
        return $this;
    }

Jurian Sluiman

Hi Mads, I think you're pointing to the bug of elided commas in IE7 (http://www.nabble.com/extra-comma-in-%7Ba:1,%7D-is-OK-td14657892.html).
Your solution adds a ":" after the last parameter, but is that correct? I think you should keep it blank :) And because I'm lazy and think it's too much work to count the items, I'd rather use arrays and the implode function:

protected function _renderEditor ()
{
    $script = 'tinyMCE.init({' . PHP_EOL

    $params = array();
    foreach ($this->_config as $name => $value) {
        if (is_array($value)) {
            $value = implode(',', $value);
        }
        if (!is_bool($value)) {
            $value = '"' . $value . '"';
        }
        $params[] = $name . ': ' . $value;
    }
    $script .= implode(',' . PHP_EOL, $params) . PHP_EOL;
    $script .= '});';

    $this->view->headScript()->appendScript($script);
    return $this;
}

I'll fix it in svn (and talking about it, I should tag the trunk asap for consistency). Thanks for the report!

Kuzma

Hi!

I wonder can I use this plugin in another way: register a view helper in bootstrap, add your 2 files and just write

in template <?php echo $this-> TinyMce() ?> in order to render TinyMce?

Thank you!

Jurian Sluiman

Kuzma, the TinyMce view helper is only meant to render the javascript at top of the page. So if you have already a textarea defined and want to enable the tinyMce window for that textarea, it's possible (but actually not recommended).

You should understand you need to set the options first ($this->tinyMce()->setOptions()) and after that render it ($this->tinyMce()->render()). It is possible to chain those methods (so you get $this->tinyMce()->setOptions()->render()).

The array of options you need to pass to the setOptions() method could be derived when you look at the TinyMce view helper class (here: http://code.google.com/p/sozfo/source/browse/trunk/library/Sozfo/View/Helper/TinyMce.php).

Branko

Paul, answer to your problem is to define helper path. You should (in Bootstrap.php) add following line

$view->addHelperPath('Sozfo/View/Helper', 'Sozfo_View_Helper');

And of course you should have Sozfo in your library path.

Kuzma

Jurian, thank you for your kind reply. I made output in that way:

echo $this->entryForm;
    $this->tinyMce()->setOptions(array(
    'label'      => 'entrybody',
    'required'   => true,
    'cols'       => '80',
    'rows'       => '24',
    'editorOptions' => new Zend_Config_Ini(APPLICATION_PATH . '/configs/tinymce.ini'
)))->render();

But my textarea is not covered by tinymce. I'm using custom form: entryForm is made of class ZFBlog_Form_EntryAdd which extends ZFBlog_Form and ZFBlog_Form extends Zend_Form. Or I making mistake and my form must extend FormTinyMce? In that way (ZFBlog_Form_EntryAdd extends Tinymce_View_Helper_FormTinyMce) I'm getting Object of class ZFBlog_Form_EntryAdd could not be converted to string error :/

Thank you!

Jurian Sluiman

Hi Kuzma. There are several objects involved in rendering the element. The element itself (Sozfo_Form_Element_TinyMce) is extending Zend_Form_Element_Textarea (the elements are 99% the same). A form element uses a view helper to render the element. For the tinyMce element, this is the Sozfo_View_Helper_FormTinyMce, extending the Zend_View_Helper_FormTextarea.

The FormTinyMce view helper renders the <textarea> html. The helper calls also the TinyMce view helper. This helper adds, based on the options set, the required javascript files (both the links to the javascript files and the inline javascript).

You should understand those view helpers (both FormTinyMce and TinyMce) are required to render the elements. You're talking about the form. You can't create a form which extends FormTinyMce because the first is a Zend_Form, the latter a view helper.

The most important thing to notice is your error message. It's talking about the entryForm form, which is a ZFBlog_Form_EntryAdd. This object has some strange things inside and that's why it throws an exception. This has nothing to do with the tinyMce rendering, because it happens bfeore you even try to convert the textarea into a TinyMce editor. If you don't know what's wrong, you could ask the people from Zend (at the mailng list) or others at e.g. zfforums.com about the problem :)
Good luck!

Kuzma

Thank you Jurian! Now everyhing works fine. It was my mistake with paths.

And I've last question about confuging TinyMce with ini files...

I'm using yours ini example and I'm doing in that way:

    $this->tinyMce()->setOptions(array(
    'mode' => 'textareas',
    'theme' => 'advanced',
    'editorOptions' => new Zend_Config_Ini(APPLICATION_PATH . '/configs/tinymce.ini','moderator')
    ))->render();

With this line:     'editorOptions' => new Zend_Config_Ini(APPLICATION_PATH . '/configs/tinymce.ini','moderator')

I'm getting an error:Catchable fatal error: Object of class Zend_Config_Ini could not be converted to string in ...View\Helper\TinyMce.php on line 155

Thank you!

Kate

Hi!
I've tried your solution but I have on problem. Everything is great, I have tinyMce editor but when I click submit the only sent data is one from original textarea. Nothing from tinyMce editor is send. Do you have any idea why it happens?
Thanks in advance for your help.
Kate

Deezmo

Hi guys! Great job!

Kate, check filters in your Zend_Form class. I think you have some filters added there (maybe StripTags or something similar). Good luck!

Emile

Hi Jurian,

Great Tutorial, but i don't know were i have to place the tiny_mce folder to get it worked?

Jurian Sluiman

Hi Emile,

The configuration has the options scriptPath and scriptFile. In this example the scriptPath is /js/tiny_mce and inside it there is the file tiny_mce.js.

If you want another path, you can configure it yourself by changing the lines in the ini file.

Emile

Hi Jurian,
Thnx for your answer, but i am getting the HTTP 500 Internal Server Error message when i try to access the form. I created the TinyMCE element as follow in my form:

$pcontent = new Zend_Form_Element_TinyMce('Page', array(
'editorOptions' => new Zend_Config_Ini(APPLICATION_PATH . '/configs/tinymce.ini', 'moderator'
)));

$pcontent->setRequired(true)
->addErrorMessage("The content field is required and can't be empty")
->setAttrib('cols', 130)
->setAttrib('rows', 30)
->addValidator('NotEmpty', true);

Thanx and regards
Emile

naada

Hi Jurian,
Thnx for your answer, but i am getting the HTTP 500 Internal Server Error message when i try to access the form. I created the TinyMCE element as follow in my form:

$pcontent = new Zend_Form_Element_TinyMce('Page', array(
'editorOptions' => new Zend_Config_Ini(APPLICATION_PATH . '/configs/tinymce.ini', 'moderator'
)));

$pcontent->setRequired(true)
              ->addErrorMessage("The content field is required and can't be empty")
              ->setAttrib('cols', 130)
              ->setAttrib('rows', 30)
              ->addValidator('NotEmpty', true);

Thanx and regards

Emile

Marko

Hello,

I read the whole tutorial and i think it is great! I managed to get Zend_Form extend Sozfo_Form without errors. In my view source I see jQuery included as well as tiny_mce.js

But i am stil just getting plain textarea instead of tinymce textarea.

Can you please give me some more directions to get it working.

Thank you in advace

NK

I'm having a problem!

I've spent many hours working in order to get TinyMCE implemented in my Zend Framework application, yet I am still uncertain about the fate of mankind!

But seriously, thank you! Great simplification of a great original project from matt.

nk

leup

Thanks Jurian & Matt for this !
I had a bad time with the path to script.

What i did :
in the config tinymce.ini
scriptPath = "js/tiny_mce/"
and in my layout phtml, i use the base meta
<base href="<?php echo $this->baseUrl();?>" />

zukras

I'm getting Error: Plugin by name 'FormTinyMce' was not found in the registry; used paths: Zend_Form_Element_: Zend/Form/Element/. Why this thing isn't explained till end. How to use this plugin creating Form element? Does it need any additional configuration to use? In the direcetory 'library/xxx/...' i have uploaded this files and in the forma i'm trying to use this plugin jus saying createElement('formTinyMce', 'description', $options).

Jurian Sluiman

Hi zukras,

This tutorial is meant for developers who know already a bit about the working principle of Zend_Form and how you're able to add additional (custom) elements to the form. It's telling more about the working principle than it allows you to copy/paste code and let it work.

In one of the comments (here: http://juriansluiman.nl/en/article/100/improved-tinymce-solution-for-the-zend-framework#r-147) I explained how you're able to manage this your own.

Because many comments on this article are about some simple bits which people do not understand, I will perhaps rewrite this article a bit. Then this tutorial is suitable to copy/paste the code and let it all work immediately.

David

Hi, I am trying to load a tinymce textarea from within a jquery ajax call.

It seems to work if I add the form direct to my page, but when I put it in a separate action (in the same controller) and have it load onclick all that shows is a textarea. it doesn't seem to be triggering the js in the <head>

I have tried forcing the headscript by calling the textarea in the main page and then call it in the ajax loaded action too.. but it only works in the main page.

I use $this->_helper->layout->disableLayout(); in my ajax page ... could this be my issue?

I gather everything is fine except the js because I still get a normal textarea feild.

Thanks

Jurian Sluiman

Hi David,

The current approach is the TinyMce view helper (Sofzo_View_Helper_TinyMce) is injecting code in the headScript view helper (Zend_View_Helper_HeadScript). Therefore, if you disable the layout which includes the headScript view helper, you never see the javascript code.

A possible alternative is to use the headScript helper directly in your ajax view, for example:

// index.ajax.phtml
<?= $this->headScript()?>
<?= $this->form?>

Where $form contains your Sofzo_Form including a TinyMCE element. The headScript is echoed in this view and thus all stored js code is placed in this view as well.

One thing you must be careful with, is when you load this controller twice or more. I don't know what will happen if you load multiple times the init code of TinyMCE...

David

Thanks for your quick response.

I have tried adding in the headscript into my ajax page. But i've noticed that when i call it from this page nothing is written to the page.

I have also tried hard coding the script into the ajax view

<pre>
<script type="text/javascript" src="/widget-as-helpers/public_html/js/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
//<!--
tinyMCE.init({
mode: "textareas",
theme: "advanced",
element_format: "html",
forced_root_block: "p",
width: "580",
height: "300",
plugins: "paste, table",
theme_advanced_resizing: "1",
theme_advanced_resizing_use_cookie: "",
theme_advanced_toolbar_location: "top",
theme_advanced_buttons1: "formatselect, bold, italic, underline, strikethrough, |, justifyleft, justifycenter, justifyright, justifyfull, |, bullist, numlist, |, outdent, indent, blockquote, |, undo, redo, cleanup, removeformat, pasteword, code ",
theme_advanced_buttons2: "link, unlink, anchor, |, image, hr , sub, sup, charmap, |, forecolor, backcolor, |, tablecontrols",
theme_advanced_buttons3: "",
theme_advanced_blockformats: "p,h1,h2,h3,blockquote,dt,dd"
}); //-->
</script>
</pre>

But when I load the ajax view everything goes blank

David

Not to worry... I have decided to load the tinymce box in the page and not in and ajax view.

One last thing (possibly asking this in the wrong place)

I would like to add an onblur event to the tnymce text area.

on a normal textarea I can use
'onblur' => "request()"
but this doesn't seem to work.

Jurian Sluiman

Hi David,

TinyMCE seems to be very tolerant at the first place, but when you try to do some more advanced tricks like ajax loading and other javascript magic, TinyMCE is often hard to work with.

About your event question, TinyMCE does support events, for example this onClick: http://tinymce.moxiecode.com/tryit/setup_editor_events.php

Perhaps it's possible for you to extend my view helper to support the events and additional setup code, but this is probably too advanced for this generic view helper so you have to work with the javascript ciode yourself and not this TinyMce view helper.

Henry

Hi,
I'm trying to get this to work but just didn't get lucky yet. I'm new to ZF so I don't exactly know what I'm doing. I've read all the comments but it didn't help me.

These are the files I added:
1) ZendFramework\library\Zend\Form\Element\TinyMce.php
2) ZendFramework\library\Zend\View\Helper\TinyMce.php
3) ZendFramework\library\Zend\View\Helper\FormTinyMce.php

I changed my code in the form to be like this:
$text_fr = $this->addElement('tinyMce', 'text_fr', array(
'filters' => array('StringTrim'),
'label' => 'Texte (FR):',
'rows' => 15,
'cols' => 60,
'editorOptions' => new Zend_Config_Ini(APPLICATION_PATH . '/configs/tinymce.ini', 'user')
));

And in Bootstrap.php I added:
$view->addHelperPath('Sozfo/View/Helper', 'Sozfo_View_Helper');

I've also tried to add $this->addPrefixPath('Sozfo_Form_', 'Sozfo/Form/'); but didn't know where. I've added the Sozfo\Form.php next to Zend in the library folder but I suppose it should be mentioned somewhere that it has to look there...
What am I missing?
It might be useful to have a step-by-step plan to add this to a project.

Anyway thanks for the effort and probably great code!

Jurian Sluiman

Hi Henry,

You need to place the Sofzo_ classes in a separate library folder. You need besides the library/Zend folder a library/Sofzo folder where you place all the classes at the right location.

So Sofzo_View_Helper_TinyMce goes into Sofzo/View/Helper/TinyMce.php etc.

Then, you need to make sure the application can find the Sofzo namespaced classes, so you need to add this line to your application.ini:

autoLoaderNameSpaces[] = "Sofzo_"

This will notifiy the autoloader and your classes will be found.

Henry

Hi,

Thanks for the reply, I got it working now but it isn't completely ok.
1) I only get 9 icons (bold, italic, underline, strikethrough, undo, redo, clean up, unordered and ordered list)
2) I get following errors in my JS-console:

Load jQuery first! tiny_mce.js:1
Uncaught TypeError: Object #<Object> has no method 'extend' tiny_mce.js:1
Uncaught TypeError: Object #<Object> has no method 'init' new:11
Uncaught TypeError: undefined is not a function tiny_mce.js:1
GET http://83.101.90.27/page/css/example.css 404 (Not Found)

jQuery is above tinymce in <head> so should be loaded before tinymce.
What is still wrong with my code?

Jurian Sluiman

Hi Henry,

I think for these issues you should contact the TinyMCE help forums. What I made is a php helper to load the TinyMCE inside a Zend_Form instance. I am not really a TinyMCE expert so I couldn't tell you why you get these errors.

What's most important is you have the TinyMCE initialization code in your <head> and that is at least there. You should have a look at the js yourself in the source of the html page.

acajaja

Hi,

A great addition to the Zend framework! Thanks for the work, however, I have to comment about the lack of documentation.

IMHO and as an Industrial Designer by training, instructions are super important. Part of any good design is to be able to articulate it to even the most non-savvy person in a way that is easy to grasp.

I've been working with ZF for many years now, and it's still not clear to me exactly how to implement Sozfo. It's been a while since I've done any customizing and have forgotten the details of implementing custom form elements. So I'm back to namespacing, prefixes, and paths and still get the pesky view helper error others have mentioned. I'm extending the Sozfo_Form successfully and have added the view helper path, so I'm not sure what the prob is.

My point is that I know it's actually fairly easy to implement Sozfo, but just write the doc and put it up with the code at Google. I think it would really almost be a 1-2-3 thing (maybe 4-5-6), but it would save a lot of people a lot of time, frustration and also bandwidth for so many searches and would also cut down on the # of posts about problems.

A truly great solution should be truly easy to implement!

Cheers!

FYI: adding the following to my ini file didn't work
<code>autoLoaderNameSpaces[] = "Sofzo_"</code>

Adding the following in my Bootstrap worked:
<code>$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Sozfo_');</code>

acajaja

Ah yes, I finally remembered what the problem is with the view helper. I'm using ZF MVC, so the layout get it's own instance of the view (not sure why yet) separate from the actual view.

So putting (abbreviated):
<code>$view->addHelperPath('path/to/your/library/Sozfo/View/Helper', 'Sozfo_View_Helper');</code>
won't work. You need to do it on the controller level or in your ACTUAL view files. So, in my controller i put:
<code>$this->view->addHelperPath('path/to/your/library/Sozfo/View/Helper', 'Sozfo_View_Helper');</code>
and that works.

Now on to the pther problems!

acajaja

Sorry, I'm trying to get out of here and wrote the last one too fast.

The corrected part is:

So putting the following in your bootstrap won't work:
<code>$view->addHelperPath('path/to/your/library/Sozfo/View/Helper', 'Sozfo_View_Helper');</code>

Jurian Sluiman

Hi acajaja,

It is right the solution is not a 1-2-3 step-by-step explanation. It's rather an article based on another solution from Matt. That's also the reason I just posted it as a follow-up and never had the idea it would become so popular.

The code is a while ago moved to github under the name of my company: https://github.com/Soflomo/Sofzo. I know there is a lack of documentation, but I think in the near future I will post another TinyMce article about integration step-by-step pointing to the updated Github code.

Ulrar

Hi,

I'm new to ZF, so I guess I just don't understand how that's supposed to work, but I can't have your thing working.

I always end up with a textarea and no javascript on the page.

I added the HelperPath and it works.

I tried the addElement you show on the post and I just have a textarea.
My form extends from Sozfo_Form.

I tried to echo the FormTinyMce helper, and same, just a textarea (without the form of course).


Can you explain clearly how I am supposed to use the herlpers ? I can't understand what is the purpose of the FormTinyMce Helper if I am supposed to use addElement.

Thanks !

Ulrar

Ha, I found the problem !

I was missing the echo headScripts() in my layout, sorry !
Seems to work quite well.

Euphorik

Hi all ,

I have a small problem, the 'required' does not work on my TinyMCE element.
I do not understand why :/
When I see the code after submit, the textarea is actually empty ... is this normal, how does it work ?

Thanks

Place a comment

If you have a user account for this site, you can login to click here.

Please note your comment below will be removed if you login!

 
 

The address is stored internally but not displayed on this site. We will respect your privacy.

In your message no html is allowd. A blank line creates a new paragraph, an url gets a hyperlink.