Back to Form class

Method findFieldsByFieldset

protected \SimpleXMLElement[]|bool
findFieldsByFieldset
(mixed $name)
Method to get an array of `<field>` elements from the form XML document which are in a specified fieldset by name.
Parameters
  • string $name The name of the fieldset.
Returns
  • \SimpleXMLElement[]|bool Boolean false on error or array of SimpleXMLElement objects.
Since
  • 1.7.0
Class: Form
Project: Joomla

Method findFieldsByFieldset - Source code

/**
 * Method to get an array of `<field>` elements from the form XML document which are in a specified fieldset by name.
 *
 * @param   string  $name  The name of the fieldset.
 *
 * @return  \SimpleXMLElement[]|boolean  Boolean false on error or array of SimpleXMLElement objects.
 *
 * @since   1.7.0
 */
protected function &findFieldsByFieldset($name)
{
    $false = false;
    // Make sure there is a valid Form XML document.
    if (!$this->xml instanceof \SimpleXMLElement) {
        throw new \UnexpectedValueException(sprintf('%s::%s `xml` is not an instance of SimpleXMLElement', \get_class($this), __METHOD__));
    }
    /*
     * Get an array of <field /> elements that are underneath a <fieldset /> element
     * with the appropriate name attribute, and also any <field /> elements with
     * the appropriate fieldset attribute. To allow repeatable elements only fields
     * which are not descendants of other fields are selected.
     */
    $fields = $this->xml->xpath('(//fieldset[@name="' . $name . '"]//field | //field[@fieldset="' . $name . '"])[not(ancestor::field)]');
    return $fields;
}