Esempio n. 1
0
 /**
  * Add a new element
  *
  * $element may be either a string element type, or an object of type
  * Zend_Form_Element. If a string element type is provided, $name must be
  * provided, and $options may be optionally provided for configuring the
  * element.
  *
  * If a Zend_Form_Element is provided, $name may be optionally provided,
  * and any provided $options will be ignored.
  *
  * @param  string|Zend_Form_Element $element
  * @param  string $name
  * @param  array|Zend_Config $options
  * @throws Zend_Form_Exception on invalid element
  * @return Zend_Form
  */
 public function addElement($element, $name = null, $options = null)
 {
     if ($element instanceof Zend_Form_Element) {
         // type string
         $exploderesult = explode('_', $element->getType());
         $type = lcfirst(trim(end($exploderesult)));
         if (null !== $options && $options instanceof Zend_Config) {
             $options = $options->toArray();
         }
         // Load default decorators
         if (null === $options || !is_array($options)) {
             $options = array();
             //Class is maybe not properly transfered to this element. We'll add class if it exists here.
             if ($element->class) {
                 $options['class'] = $element->class;
             }
         }
         if (!array_key_exists('decorators', $options)) {
             $decorators = $this->getDefaultDecoratorsByElementType($type);
             if (!empty($decorators)) {
                 $options['decorators'] = $decorators;
             }
         }
         // Elements type use 'form-control' class
         $element_fc = array('text', 'password', 'dateTime', 'dateTimeLocal', 'date', 'month', 'time', 'week', 'number', 'email', 'url', 'search', 'tel', 'color', 'textarea', 'select', 'multiselect');
         if (in_array($type, $element_fc)) {
             if (null === $options) {
                 $options = array('class' => 'form-control');
             } elseif (array_key_exists('class', $options)) {
                 if (!strstr($options['class'], 'form-control')) {
                     $options['class'] .= ' form-control';
                     $options['class'] = trim($options['class']);
                 }
             } else {
                 $options['class'] = 'form-control';
             }
         }
         $element->setOptions($options);
     }
     parent::addElement($element, $name, $options);
 }