array('form-group' => true), ); protected $_title; protected $_inputs = array(); protected $_labelTarget; protected $_help; protected $_helpParams = array(); public function __construct($title) { $this->_title = $title; } public function add(Form_Input $input) { array_push($this->_inputs, $input); $input->_setParent($this); // Defaults to first input if (!isset($this->_labelTarget)) $this->_labelTarget = $input; return $input; } public function setLabelTarget(Form_Input $input) { $this->_labelTarget = $input; } public function setHelp($help, array $params = array()) { $this->_help = $help; $this->_helpParams = $params; return $this; } public function enableDuplication($max = null, $horiz = false) { if($horiz) $this->addClass('user-duplication-horiz'); // added buttons are 2 cols wide with no offset else $this->addClass('user-duplication'); // added buttons 10 cols wide with 2 col offset if (isset($max)) $this->_attributes('data-duplicate-max', $max); foreach ($this->_inputs as $input) $input->setIsRepeated(); return $this; } protected function _getHelp() { if (empty($this->_help)) return null; $group = new Form_Element; $group->addClass('col-sm-'. Form::MAX_INPUT_WIDTH, 'col-sm-offset-'. Form::LABEL_WIDTH); $help = gettext($this->_help); if (!empty($this->_helpParams)) $help = call_user_func_array('sprintf', array_merge([$help], $this->_helpParams)); return << {$help} EOT; } public function __toString() { global $config; $element = parent::__toString(); // Automatically determine width for inputs without explicit set $spaceLeft = Form::MAX_INPUT_WIDTH; $missingWidth = array(); foreach ($this->_inputs as $input) { if (count($this->_inputs) > 1 && !$input->hasAttribute('placeholder')) $input->setPlaceholder($input->getTitle()); $width = $input->getWidth(); if (isset($width)) $spaceLeft -= $width; else array_push($missingWidth, $input); } foreach ($missingWidth as $input) $input->setWidth($spaceLeft / count($missingWidth)); if (strtolower($this->_labelTarget->getType()) == 'hidden') $hidden = true; $form_controls = array('input', 'select', 'button', 'textarea', 'option', 'optgroup', 'fieldset', 'label'); if (in_array(strtolower($this->_labelTarget->getTagName()), $form_controls) && !$hidden) $target = $this->_labelTarget->getId(); $inputs = implode('', $this->_inputs); $help = $this->_getHelp(); if (!isset($config['system']['webgui']['webguileftcolumnhyper'])) $target = null; $label = new Form_Element('label', false, ['for' => $target]); $label->addClass('col-sm-'.Form::LABEL_WIDTH, 'control-label'); if (!empty(trim($this->_title)) || is_numeric($this->_title)) { $title = htmlspecialchars(gettext($this->_title)); } return << {$inputs} {$help} EOT; } }