private function _addWidget($id) { // Avoid duplicates if ($this->_form->elementExists($id)) { return; } $field =& $this->fields[$id]; $default = TIP::pickElement($id, $this->_defaults); // By default, fields starting with '_' and automatic fields // cannot be edited, so are included as hidden (if defined) if (substr($id, 0, 1) == '_' || $field['automatic']) { is_null($default) || $this->_form->addElement('hidden', $id, $default); return; } $flags = isset($field['flags']) ? explode(',', strtolower($field['flags'])) : array(); $explicit_default = TIP::pickElement($id, $this->defaults); // Check for "placeholder" flag if (is_null($explicit_default) && in_array('placeholder', $flags)) { // Special case: placeholder flag and no default value provided // The widget must not be built. The value will be automagically // handled by _converterPlaceholder() $this->_transaction_protected = true; $this->_addConverter($id, 'Placeholder'); return; } // Create the widget $old_tabindex = $this->_tabindex; $method = '_widget' . @$field['widget']; method_exists($this, $method) || ($method = '_widgetText'); $element =& $this->{$method}($field, @$field['widget_args']); // Check for "immutable" flag and explicit default value provided if (!is_null($explicit_default) && in_array('immutable', $flags)) { $element->freeze(); } // Check if the field is in the "readonly" list if (in_array($id, $this->readonly)) { $element->freeze(); } // Remove the element on "trailing" flag set: // the element will be appended in the render() method if (in_array('trailing', $flags)) { $this->_trailing_elements[$id] =& $element; $this->_form->removeElement($id, false); $this->_tabindex = $old_tabindex; } }