I created a custom controller where I insert a form:
my.routing.yml:
aw_candidacy_check.politician.attendance_form:
path: '/cc/{parliament_period}'
defaults:
_controller: '\Drupal\aw_candidacy_check\Controller\PoliticianAttendance::build'
requirements:
_custom_access: '\Drupal\aw_candidacy_check\AccessHandler\PoliticianAttendanceAccess::access'
In the controller the form is rendered in this way:
\Drupal::formBuilder()->getForm('\Drupal\aw_candidacy_check\Form\PositionsForm', $this->candidacyCheck, $this->attendance);
The arguments are derived from the given parliament_period
routing parameter. The form's buildForm
method looks like:
public function buildForm(array $form, FormStateInterface $form_state, CandidacyCheck $candidacy_check = NULL, CCAttendance $attendance = NULL) {
$form['actions'] = [
'#type' => 'actions'
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => 'Speichern'
];
return $form;
The submitForm
method does nothing. Every time I submit this form I get an exception thrown in FormBuilder->buildForm() in line 352:
if ($response instanceof Response) {
throw new EnforcedResponseException($response);
}
Somewhere on the journey the $response is created and it is correctly the path of my controller. Why is this exception thrown? What do I miss or what is wrong with my controller / form class?