_fields[$key] = [ 'name' => $label, 'type' => $type, 'value' => $value, 'required' => $required, 'placeholder' => $placeholder ?? $label, 'info' => $info ?? '', 'options' => [], 'order' => $order ?? count($this->_fields), ]; } /** * Add a option to a field. * * @param string $field Add the option to this field. * @param string $value Field value. * @param string $option The option to display. */ public function addOption(string $field, string $value, string $option): void { if (isset($this->_fields[$field])) { $this->_fields[$field]['options'][] = [ 'value' => $value, 'option' => $option, ]; } } /** * List all fields, sorted by their order. * * @return array List of fields. */ public function getAll(): iterable { $fields = $this->_fields; uasort($fields, static function ($a, $b) { return $a['order'] - $b['order']; }); return $fields; } }