API16

JForm/loadFieldsXML: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
New page: ===Description=== Loads form fields from an XML fields element optionally reseting fields before loading new ones. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>...
 
m preparing for archive only
 
(3 intermediate revisions by 2 users not shown)
Line 2: Line 2:
Loads form fields from an XML fields element optionally reseting fields before loading new ones.
Loads form fields from an XML fields element optionally reseting fields before loading new ones.


<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JForm/loadFieldsXML|Edit Descripton]]<nowiki>]</nowiki>
</span>


{{Description:JForm/loadFieldsXML}}
 
<! removed transcluded page call, red link never existed >


===Syntax===
===Syntax===
Line 17: Line 15:
!Description
!Description
|-
|-
|  
| &$xml
|  
|  
|  $xml The XML fields object.  
|  $xml The XML fields object.  
Line 137: Line 135:
</source>
</source>


<span class="editsection" style="font-size:76%;">
 
<nowiki>[</nowiki>[[SeeAlso:JForm/loadFieldsXML|Edit See Also]]<nowiki>]</nowiki>
<! removed transcluded page call, red link never existed >
</span>
{{SeeAlso:JForm/loadFieldsXML}}


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=loadFieldsXML
  category=loadFieldsXML
  category=JForm
  category=JForm
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*
  format= ,,,
  format= ,,,
</dpl>
</dpl>
[[Category:Archived pages API16]]

Latest revision as of 01:41, 25 March 2017

Description

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


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

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


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

Examples

Code Examples