core/lib/Drupal/Core/Form/FormBuilder.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index ba8c055..7ba808b 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -647,9 +647,7 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state) { // Only update the action if it is not already set. if (!isset($form['#action'])) { - $form['#action'] = $this->buildFormAction(); - $form['#cache']['contexts'][] = 'url.path'; - $form['#cache']['contexts'][] = 'url.query_args'; + $form = $this->buildFormAction($form); } // Fix the form method, if it is 'get' in $form_state, but not in $form. @@ -759,10 +757,13 @@ public function prepareForm($form_id, &$form, FormStateInterface &$form_state) { /** * Builds the $form['#action']. * - * @return string - * The URL to be used as the $form['#action']. + * @param array $form + * An associative array containing the structure of the form. + * + * @return array + * The updated form array. */ - protected function buildFormAction() { + protected function buildFormAction($form) { // @todo Use instead of the master request in // https://www.drupal.org/node/2505339. $request = $this->requestStack->getMasterRequest(); @@ -778,7 +779,13 @@ protected function buildFormAction() { // https://www.drupal.org/node/2504709. $parsed = UrlHelper::parse($request_uri); unset($parsed['query'][static::AJAX_FORM_REQUEST], $parsed['query'][MainContentViewSubscriber::WRAPPER_FORMAT]); - return $parsed['path'] . ($parsed['query'] ? ('?' . UrlHelper::buildQuery($parsed['query'])) : ''); + $action = $parsed['path'] . ($parsed['query'] ? ('?' . UrlHelper::buildQuery($parsed['query'])) : ''); + + $form['#action'] = $action; + $form['#cache']['contexts'][] = 'url.path'; + $form['#cache']['contexts'][] = 'url.query_args'; + + return $form; } /**