public function buildForm($form_arg, FormStateInterface &
$form_state) { // Ensure the form ID is prepared.
$form_id =
$this->
getFormId($form_arg,
$form_state);
$request =
$this->requestStack->
getCurrentRequest();
// Inform $form_state about the request method that's building it, so that
// it can prevent persisting state changes during HTTP methods for which
// that is disallowed by HTTP: GET and HEAD.
$form_state->
setRequestMethod($request->
getMethod());
// Initialize the form's user input. The user input should include only the
// input meant to be treated as part of what is submitted to the form, so
// we base it on the form's method rather than the request's method. For
// example, when someone does a GET request for
// /node/add/article?destination=foo, which is a form that expects its
// submission method to be POST, the user input during the GET request
// should be initialized to empty rather than to ['destination' => 'foo'].
$input =
$form_state->
getUserInput();
if (!
isset($input)) { $input =
$form_state->
isMethodType('get'
) ?
$request->query->
all() :
$request->request->
all();