Back to Form class

Method getFieldset

public \Joomla\CMS\Form\FormField[]
getFieldset
(mixed $set = null)
Method to get an array of FormField objects in a given fieldset by name. If no name is given then all fields are returned.
Parameters
  • string $set The optional name of the fieldset.
Returns
  • \Joomla\CMS\Form\FormField[] The array of FormField objects in the fieldset.
Since
  • 1.7.0
Class: Form
Project: Joomla

Method getFieldset - Source code

/**
 * Method to get an array of FormField objects in a given fieldset by name.  If no name is
 * given then all fields are returned.
 *
 * @param   string  $set  The optional name of the fieldset.
 *
 * @return  FormField[]  The array of FormField objects in the fieldset.
 *
 * @since   1.7.0
 */
public function getFieldset($set = null)
{
    $fields = [];
    // Get all of the field elements in the fieldset.
    if ($set) {
        $elements = $this->findFieldsByFieldset($set);
    } else {
        $elements = $this->findFieldsByGroup();
    }
    // If no field elements were found return empty.
    if (empty($elements)) {
        return $fields;
    }
    // Build the result array from the found field elements.
    foreach ($elements as $element) {
        // Get the field groups for the element.
        $attrs = $element->xpath('ancestor::fields[@name]/@name');
        $groups = array_map('strval', $attrs ?: []);
        $group = implode('.', $groups);
        // If the field is successfully loaded add it to the result array.
        if ($field = $this->loadField($element, $group)) {
            $fields[$field->id] = $field;
        }
    }
    return $fields;
}