API16

JForm/loadFieldsXML

From Joomla! Documentation

< API16:JForm

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Loads form fields from an XML fields element optionally reseting fields before loading new ones.


<! removed transcluded page call, red link never existed >

Syntax[edit]

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[edit]

boolean True on success, false otherwise.

Defined in[edit]

libraries/joomla/form/form.php

Importing[edit]

jimport( 'joomla.form.form' );

Source Body[edit]

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;
}


<! removed transcluded page call, red link never existed >

Examples[edit]

Code Examples[edit]