In the submitForm
of a custom form, I have this:
$sFileName = 'sites/default/files/_private/bulletins/' . $form_state->getValue('adherent')[1] . ".pdf";
$response = new BinaryFileResponse($sFileName);
$response->setContentDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
'bulletin.pdf'
);
$form_state->setResponse($response);
This triggers the download of a pdf document and it works.
Then, I try to execute:
$form_state->setRedirect('<front>');
and that is not working!
In FormState::setResponse
documentation, I read « If a response is set, it will be used during processing and returned directly. The form will not be rebuilt or redirected ».
I guess it is why my redirection to doesn't work...
How can I do it anyway?