Horde_Form::insertVariableBefore PHP Method

insertVariableBefore() public method

TODO
public insertVariableBefore ( $before, $humanName, $varName, $type, $required, $readonly = false, $description = null, $params = [] )
    function insertVariableBefore($before, $humanName, $varName, $type, $required, $readonly = false, $description = null, $params = array())
    {
        $type = $this->getType($type, $params);
        $var = new Horde_Form_Variable($humanName, $varName, $type, $required, $readonly, $description);
        /* Set the form object reference in the var. */
        $var->setFormOb($this);
        if ($var->getTypeName() == 'enum' && !strlen($type->getPrompt()) && count($var->getValues()) == 1) {
            $vals = array_keys($var->getValues());
            $this->_vars->add($var->varName, $vals[0]);
            $var->_autofilled = true;
        } elseif ($var->getTypeName() == 'file' || $var->getTypeName() == 'image') {
            $this->_enctype = 'multipart/form-data';
        }
        if (empty($this->_currentSection) && $this->_currentSection !== 0) {
            $this->_currentSection = '__base';
        }
        if (is_null($before)) {
            $this->_variables[$this->_currentSection][] =& $var;
        } else {
            $num = 0;
            while (isset($this->_variables[$this->_currentSection][$num]) && $this->_variables[$this->_currentSection][$num]->getVarName() != $before) {
                $num++;
            }
            if (!isset($this->_variables[$this->_currentSection][$num])) {
                $this->_variables[$this->_currentSection][] =& $var;
            } else {
                $this->_variables[$this->_currentSection] = array_merge(array_slice($this->_variables[$this->_currentSection], 0, $num), array(&$var), array_slice($this->_variables[$this->_currentSection], $num));
            }
        }
        return $var;
    }