ZF-10960: Zend_Dojo_Form_Element_Editor doesn't accept more than one separator ( char | ) in toolbar
Description
Hi,
I discovered bug in Zend_Dojo_Form_Element_Editor in function addPlugin(). When I try add more than one separator in dijit.Editor toolbar, so only one separator will be added, because this condition:
if (in_array($plugin, $plugins)) {
return $this;
}
So, when in the $plugin variable is the string | ( it's the separator for dijit.Editor toolbar ), so the next separator will not be added into the dijit.Editor toolbar.
Here is the example, in ->setPlugins() is more than one separator ( e.g. 'undo', 'redo', '|', 'copy', 'cut', '|', 'bold', '|', 'createLink' ), so there are 3 separators '|', but in dijit.Editor toolbar is displayed only one separator:
$introtext = new Zend_Dojo_Form_Element_Editor('introtext');
$introtext
->setLabel('Popis k Upútavke:')
->setRequired(false)
->setOptions(array(
))
->setPlugins(array(
'undo', 'redo', '|', 'copy', 'cut', 'paste', '|', 'bold', 'italic', 'underline', 'strikethrough', '|',
'createLink', 'dijit._editor.plugins.LinkDialog', 'dijit._editor.plugins.EnterKeyHandling'
))
->setHeight('140px')
->addValidators(array(
new Zend_Validate_StringLength(
array(
'max' => 255
)
)
))
->addFilters(array(
new Zend_Filter_PregReplace(
array(
'match' => '/
/i',
'replace' => ''
)
)
));
And here is the patch:
/**
* Add a single editor plugin
*
* @param string $plugin
* @return Zend_Dojo_Form_Element_Editor
*/
public function addPlugin($plugin)
{
$plugin = (string) $plugin;
$plugins = $this->getPlugins();
if (in_array($plugin, $plugins) && ($plugin !== '|')) {
return $this;
}
$plugins[] = (string) $plugin;
$this->setDijitParam('plugins', $plugins);
return $this;
}
In this patch is changed this line, from:
if (in_array($plugin, $plugins)) {
to:
if (in_array($plugin, $plugins) && ($plugin !== '|')) {
Thank you for the fix in next ZF release.
Comments
Posted by Robert Basic (robertbasic) on 2011-04-22T11:12:26.000+0000
Bug confirmed and attaching the patch as per the description.
Posted by Robert Basic (robertbasic) on 2011-04-22T15:02:03.000+0000
Attaching tests.
Posted by Ralph Schindler (ralph) on 2011-04-28T17:49:12.000+0000
Fixed in r23873 in trunk and r23874 in release branch 1.11
Posted by Robert Basic (robertbasic) on 2011-07-28T19:34:03.000+0000
Pull request to import the patch to ZF2 is sent https://github.com/zendframework/zf2/pull/289