Exemplo n.º 1
0
 /**
  * @see Zend_Form::addElement
  *
  * We have to override this, because we have to set some special decorators
  * on a per-element basis (checkboxes and submit buttons have different
  * decorators than other elements)
  *
  * @param string|Zend_Form_Element $element
  * @param string $name
  * @param array|Zend_Config $options
  */
 public function addElement($element, $name = null, $options = null)
 {
     $element->setDisableLoadDefaultDecorators(true);
     parent::addElement($element, $name, $options);
     if (!$element instanceof Zend_Form_Element && $name !== null) {
         $element = $this->getElement($name);
     } else {
         $element->setDecorators($this->_getDefaultElementDecorator($element));
     }
     if ($element instanceof Zend_Form_Element_File) {
         $this->setAttrib('enctype', Zend_Form::ENCTYPE_MULTIPART);
         if (!$element->getDescription()) {
             $element->setDescription('Add File...');
         }
     }
     if ($element instanceof Zend_Form_Element_Submit || $element instanceof Zend_Form_Element_Reset || $element instanceof Zend_Form_Element_Button) {
         if (!$element instanceof Zend_Form_Element_Reset && !$element instanceof Zend_Form_Element_Button) {
             $class = 'btn-primary';
         } else {
             if ($element instanceof Zend_Form_Element_Button && $element->getAttrib('type') === 'submit') {
                 $class = 'btn-primary';
             } else {
                 $class = 'btn-default';
             }
         }
         $element->setAttrib('class', trim('btn ' . $class . ' ' . $element->getAttrib('class')));
         $this->_addActionsDisplayGroupElement($element);
     } else {
         $element->setAttrib('class', trim('form-control ' . $element->getAttrib('class')));
     }
     if ($element instanceof Zend_Form_Element_Radio || $element instanceof Zend_Form_Element_MultiCheckbox) {
         $multiOptions = array();
         foreach ($element->getMultiOptions() as $value => $label) {
             $multiOptions[$value] = ' ' . $label;
         }
         $element->setMultiOptions($multiOptions);
         $element->setAttrib('labelclass', 'checkbox');
         if ($element->getAttrib('inline')) {
             $element->setAttrib('labelclass', 'checkbox inline');
         }
         if ($element instanceof Zend_Form_Element_Radio) {
             $element->setAttrib('labelclass', 'radio');
         }
         if ($element->getAttrib('inline')) {
             $element->setAttrib('labelclass', 'radio inline');
         }
         $element->setOptions(array('separator' => ''));
     }
     if ($element instanceof Zend_Form_Element_Hidden) {
         $element->setDecorators(array('ViewHelper'));
     }
     if ($element instanceof Zend_Form_Element_Textarea && !$element->getAttrib('rows')) {
         $element->setAttrib('rows', 3);
     }
     if ($element->isRequired()) {
         $element->setAttrib('required', 'required');
     }
     return $this;
 }