A fix
I just retried by described attempt to call buildForm
instead of getForm
.
Again I got into the redirect loop. But aperently that happens because I gave my submit button type submit
instead of button
.
So when I change my submit button to:
$form['actions']['submit'] = [
'#name' => 'test-submit',
'#id' => Html::getUniqueId('edit-submit-test-form'),
'#type' => 'button',
'#value' => 'Submit it',
];
And I call:
$form = new TestForm();
$form_state = new \Drupal\Core\Form\FormState();
$form_state->setMethod('GET');
$variables['test_form'] = \Drupal::formBuilder()->buildForm($form, $form_state);
It now all works (Drupal picks up the GET request and processes the form). It's still not what I'm expecting of it, but that's a whole other question, so I'll open a new question instead.