I'm building a form and setting values via
$form = \Drupal::formBuilder()->getForm('My\Module', ['key1' => 'x']);
where I set the passed key1
as the default values for the associated fields : in My\Module\buildForm
, you would find
public function buildForm(array $form, FormStateInterface $form_state, $presets = array()) {
$form['key1'] = [
'#type' => 'textfield',
'#default_value' => isset($presets['key1']) ? $presets['key1'] : $query->get('key1')
];
return $form;
}
This takes place in a controller not directly related to the form and I'd like to retrieve all values set, either as defaults or as parameters of the page, something like ['key1' => 'x']
if no parameter is passed to the page or ['key1' => 'v1']
if the page is called with ?key1=v1
How can I get all the values on my form array (besides filtering on the field names)?