Issues

ZF-11257: setIsArray does not work with decorators

Issue Type: Bug Created: 2011-04-03T20:53:32.000+0000 Last Updated: 2011-04-05T09:54:13.000+0000 Status: Closed Fix version(s): Reporter: Mickael Monsieur (mickaelmonsieur) Assignee: Kai Uwe (kaiuwe) Tags: - Zend_Form

Related issues: Attachments:

Description

Everything is in the title. Zend_Form->setIsArray does not work with decorators.

<pre class="highlight">
        $screen_name = $this->createElement('text','screen_name')
                ->addFilter('stringTrim')
                ->addFilter('stripTags')
                ->setIsArray(true);

result is :

<pre class="highlight">
        $screen_name = $this->createElement('text','screen_name')
                ->addFilter('stringTrim')
                ->addFilter('stripTags')
                ->setDecorators(array('Col'))
                ->setIsArray(true);

result is :

the [] disappears...

Comments

Posted by Kai Uwe (kaiuwe) on 2011-04-04T18:21:00.000+0000

The standard decorators from Zend_Form doesn't include a decorator with the name "Col". Please publish your decorator.

Posted by Mickael Monsieur (mickaelmonsieur) on 2011-04-05T08:24:30.000+0000

<pre class="highlight">
<?php
class Lovonair_Form_Decorator_Col extends Zend_Form_Decorator_Abstract  implements Zend_Form_Decorator_Marker_File_Interface  
{
    public function buildLabel()
    {
        $element = $this->getElement();
        $label = $element->getLabel();
        if ($translator = $element->getTranslator()) {
            $label = $translator->translate($label);
        }
        if ($element->isRequired()) {
            $label .= '*';
        }
        $label .= '';
        $messages = $element->getMessages();   
        if (empty($messages)){
             return $element->getView()
                       ->formLabel($element->getName(), $label);
        }else{
             return $element->getView()
                       ->formLabel($element->getName(), $label, array('class'=>'error'));
        }
    }

    public function buildInput()
    {
        $element = $this->getElement();
        $helper  = $element->helper;
                   
            return $element->getView()->$helper(
                $element->getName(),
                $element->getValue(),
                $element->getAttribs(),
                $element->options
            );
        
    }

    public function buildErrors()
    {
        $element  = $this->getElement();
        $messages = $element->getMessages();        
        if (empty($messages)) {
            return '';
        }
        $return = '';     
           
        foreach($messages as $mess){
         $return .= '

' . $mess . '

';      
        }
        return $return;
    }

    public function buildDescription()
    {
        $element = $this->getElement();
        $desc    = $element->getDescription();
        if (empty($desc)) {
            return '';
        }
        return '

' . $desc . '

';
    }

    public function render($content)
    {         
        $element = $this->getElement();
        if (!$element instanceof Zend_Form_Element) {
            return $content;
        }
        if (null === $element->getView()) {
            return $content;
        }
        
    
        $separator = $this->getSeparator();
        $placement = $this->getPlacement();
        $label     = $this->buildLabel();
        $input     = $this->buildInput();
        $errors    = $this->buildErrors();
        $desc      = $this->buildDescription();
        if(!empty($errors)) $errorClass = " formRed"; else $errorClass = "";       
        if(!empty($this->_options) && isset($this->_options['class'])) $class = ' '.$this->_options['class']; else $class='';
        if(!empty($this->_options) && isset($this->_options['id'])) $id = ' id="'.$this->_options['id'].'"'; else $id='';
        if(!empty($this->_options) && isset($this->_options['style'])) $style = ' style="'.$this->_options['style'].'"'; else $style='';
        
        if($element instanceof Zend_Form_Element_MultiCheckbox){ 
            $inputr = '
';
            $inputr .= $input;
            $inputr .= '


';
            $input = $inputr; 
        } 
        
        if($element instanceof Zend_Form_Element_Submit || $element instanceof Zend_Form_Element_Button){
        
          $output = '
'
                  . '<span class="btn'.$class.'">
                        <span class="btnBkg"></span>'                             
                  . $input   
                  . '</span>'  
                  . '


';   
               
        }elseif($element instanceof Zend_Form_Element_Checkbox && (isset($this->_options['type']) && $this->_options['type']=='term')){
         $output = '
'
                . '
'
                . ''.$input.' '.$element->getLabel().''
                . '

'
                . $errors        
                . '

``

'           
                . '


';
        }else{   
        $output = '
'
                . '

'.$label.'

'                  
                . '

'.$input.'

' 
                . $desc
                . $errors        
                . '

``

'     
                . '


';
        }

        switch($placement) {
            case (self::PREPEND):
                return $output . $separator . $content;
            case (self::APPEND):
            default:
                return $content . $separator . $output;
        }
    }
}

Posted by Kai Uwe (kaiuwe) on 2011-04-05T09:49:34.000+0000

This is a bug in your decorator and not in the framework!

Please check the default decorators:

<pre class="highlight">
class Zend_Form_Decorator_ViewHelper extends Zend_Form_Decorator_Abstract
{
    // …

    public function render($content)
    {
        // …
        
        $name = $element->getFullyQualifiedName();
        
        // …
    }
}

Or look a the API-Doc: [http://framework.zend.com/apidoc/core/…]

Posted by Kai Uwe (kaiuwe) on 2011-04-05T09:54:13.000+0000

For a error in the documentation open a new issue. Thanks.

[http://framework.zend.com/manual/en/…]

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts