ZF-11380: Zend_Form_Decorator_HtmlTag::_htmlAttribs doesn't accept class methods as attribute callback

Description

It seems, that Zend_Form_Decorator_HtmlTag::_htmlAttribs() method doesn't accept class methods as attribute callback. For example the following code will not cause later rendering of "class" attribute as it could be expected:


class Some_Class {
  public function someMethod($decorator) {
    return 'someClass';
  }
}
...
$obj = new Some_Class();
$someFormElement->addDecorator(
 array('myHtmlTag'=>'HtmlTag'),
 array('tag'=>'div', 
       'class' => array('callback' => array($obj,'someMethod')))
);

The solution may be to slightly patch the "Zend/Form/Decorator/HtmlTag" with the following patch:


--- Zend/Form/Decorator/HtmlTag.php 2011-03-01 18:25:24.000000000 +0100
+++ Zend-Patched/Form/Decorator/HtmlTag.php 2011-05-14 14:49:29.000000000 +0200
@@ -86,7 +86,7 @@
             if (is_array($val)) {
                 if (array_key_exists('callback', $val)
                     && is_callable($val['callback'])) {
-                    $val = $val['callback']($this);
+                    $val = call_user_func($val['callback'],$this);
                 } else {
                     $val = implode(' ', $val);
                 }

The patch makes _htmlAttribs() to use "call_user_func" to call user-provided callback.

Comments

No comments to display