Issues

ZF-9010: Erros decorator on Zend_Form when grouped does not translate labels

Description

When you want to group the errors decorator on form the labels are not translated.

Example:

class Form_BugForm extends Zend_Form { function __construct( $options = NULL ) { parent::__construct($options); $this->setName('formName') ->setMethod('post');

    $element = new Zend_Form_Element_Text('foo');
    $element->setRequired(true)
            ->setLabel('Foo label')
            ->addValidator('NotEmpty')
            ->removeDecorator('Errors');

    $this->addElement($element);

    $this->setDecorators(array('FormElements', 'Form', 'FormErrors'));
}

}

Label 'Foo label' is not translated in the FormErrors decorator.

Our solution: (library/Zend/Form/Decorator/FormErrors.php)

public function renderLabel(Zend_Form_Element $element, Zend_View_Interface $view) { $label = $element->getLabel(); if (empty($label)) { $label = $element->getName(); }

    /* We solved the bug with adding this if */
    if (null !== ($translator = $element->getTranslator())) {
        $label = $translator->translate($label);
    }

    return $this->getMarkupElementLabelStart()
         . $view->escape($label)
         . $this->getMarkupElementLabelEnd();
}

Comments

This is a duplicate of ZF-8713