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