2 /* This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier,
3 and is published under the AGPL license. */
5 abstract class Syj_Form_TableAbstract extends Zend_Form
7 protected $_elementDecorators = array(
9 array(array('td' => 'HtmlTag'), array('tag' => 'td', 'style' => 'width: 100%' )),
10 array('label', array('tag' => 'td')),
11 array(array('tr' => 'HtmlTag'), array('tag' => 'tr')),
12 array('TableDescription'));
14 protected $_decorators = array(
15 'FormErrors' => array('decorator' => 'FormErrors', 'options' => null),
16 'FormElements' => array('decorator' => 'FormElements', 'options' => null),
17 'Form' => array('decorator' => 'Form', 'options' => null),
20 protected $_displaygroupDecorators = array(
22 array('HtmlTag', array('tag' => 'table')));
24 protected $_defaultClassName = "form-table-elem";
26 public function __construct($options = null) {
27 $this->addPrefixPath('Syj_Form_Decorator', APPLICATION_PATH . '/forms/decorator/', 'decorator');
28 parent::__construct($options);
31 protected function setMainElements(array $elements) {
32 $this->setElements($elements);
33 $this->addDisplayGroup(array_map(function ($elem) { return $elem[1]; }, $elements), 'data');
34 $this->setDisplayGroupDecorators($this->_displaygroupDecorators);
39 public function addElement($element, $name = null, $options = null)
41 $res = parent::addElement($element, $name, $options);
42 if ($element instanceof Zend_Form_Element) {
43 $name = $element->getName();
45 $element = $this->_elements[$name];
46 if ($element instanceof Zend_Form_Element_Text or $element instanceof Zend_Form_Element_Password) {
47 if ($this->getAttrib('class') === null) {
48 $element->setAttrib('class', $this->_defaultClassName);
50 } else if ($element instanceof Zend_Form_Element_Submit) {
51 $element->setDecorators(array(
53 array('Description', array('tag' => '')),
54 array('HtmlTag', array('tag' => 'p', 'class' => 'center')),