You are here

protected function FormBuilder::buildFormAction in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Form/FormBuilder.php \Drupal\Core\Form\FormBuilder::buildFormAction()
  2. 9 core/lib/Drupal/Core/Form/FormBuilder.php \Drupal\Core\Form\FormBuilder::buildFormAction()

Builds the $form['#action'].

Return value

string The URL to be used as the $form['#action'].

File

core/lib/Drupal/Core/Form/FormBuilder.php, line 845

Class

FormBuilder
Provides form building and processing.

Namespace

Drupal\Core\Form

Code

protected function buildFormAction() {

  // @todo Use <current> instead of the main request in
  //   https://www.drupal.org/node/2505339.
  $request = $this->requestStack
    ->getMainRequest();
  $request_uri = $request
    ->getRequestUri();

  // Prevent cross site requests via the Form API by using an absolute URL
  // when the request uri starts with multiple slashes..
  if (strpos($request_uri, '//') === 0) {
    $request_uri = $request
      ->getUri();
  }

  // @todo Remove this parsing once these are removed from the request in
  //   https://www.drupal.org/node/2504709.
  $parsed = UrlHelper::parse($request_uri);
  unset($parsed['query'][static::AJAX_FORM_REQUEST], $parsed['query'][MainContentViewSubscriber::WRAPPER_FORMAT]);
  $action = $parsed['path'] . ($parsed['query'] ? '?' . UrlHelper::buildQuery($parsed['query']) : '');
  return UrlHelper::filterBadProtocol($action);
}