API16:JForm/loadFieldsXML
From Joomla! Documentation
Contents |
Description
Loads form fields from an XML fields element optionally reseting fields before loading new ones.
Description:JForm/loadFieldsXML
Syntax
loadFieldsXML(&$xml, $reset=true, $parent=null)
| Parameter Name | Default Value | Description |
|---|---|---|
| &$xml | $xml The XML fields object. | |
| $reset | true | $reset Flag to toggle whether the form groups should be reset. |
| $parent | null |
Returns
boolean True on success, false otherwise.
Defined in
libraries/joomla/form/form.php
Importing
jimport( 'joomla.form.form' );
Source Body
public function loadFieldsXML(&$xml, $reset = true, $parent = null) { // Check for an XML object. if (!is_object($xml)) { return false; } // Get the group name. $group = ((string)$xml->attributes()->group) ? (string)$xml->attributes()->group : '_default'; // Initialise the data group. if ($reset) { $this->_data[$group] = array(); } else { if (!isset($this->_data[$group])) { $this->_data[$group] = array(); } } if(!isset($this->_fieldsets[$group])) { // Get the fieldset attributes. $this->_fieldsets[$group] = array(); } if($parent && $value = (string) $xml->attributes()->group) { $this->_fieldsets[$parent]['children'][] = $value; $this->_fieldsets[$group]['parent'] = $parent; } // Get the fieldset label. if ($value = (string)$xml->attributes()->label) { $this->_fieldsets[$group]['label'] = $value; } // Get the fieldset description. if ($value = (string)$xml->attributes()->description) { $this->_fieldsets[$group]['description'] = $value; } // Get an optional hidden setting (at the discretion of the renderer to honour). if ($value = (string)$xml->attributes()->hidden) { $this->_fieldsets[$group]['hidden'] = ($value == 'true' || $value == 1) ? true : false; } // Get the fieldset array option. $array = (string)$xml->attributes()->array; if ($array=='true') { $this->_fieldsets[$group]['array'] = true; } elseif($array=='false' || empty($array)) { $this->_fieldsets[$group]['array'] = false; } else { $this->_fieldsets[$group]['array'] = $array; } // Check if there is a field path to handle. if ((string)$xml->attributes()->addfieldpath) { jimport('joomla.filesystem.folder'); jimport('joomla.filesystem.path'); $path = JPath::clean(JPATH_ROOT.DS.$xml->attributes()->addfieldpath); // Add the field path to the list if it exists. if (JFolder::exists($path)) { self::addFieldPath($path); } } if ($reset) { // Reset the field group. $this->_groups[$group] = array(); if($xml->fields) { $this->loadFieldsXML($xml->fields, $reset, $group); } // Add the fields to the group. foreach ($xml->field as $field) { $this->_groups[$group][(string)$field->attributes()->name] = $field; } } else { if($xml->fields) { $this->loadFieldsXML($xml->fields, $reset, $group); } // Add to the field group. foreach ($xml->field as $field) { $this->_groups[$group][(string)$field->attributes()->name] = $field; } } return true; }
[Edit See Also] SeeAlso:JForm/loadFieldsXML