W3cubDocs

/Drupal 8

protected function FormBuilder::buildFormAction

protected 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 826

Class

FormBuilder
Provides form building and processing.

Namespace

Drupal\Core\Form

Code

protected function buildFormAction() {
  // @todo Use <current> instead of the master request in
  //   https://www.drupal.org/node/2505339.
  $request = $this->requestStack->getMasterRequest();
  $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]);
  return $parsed['path'] . ($parsed['query'] ? ('?' . UrlHelper::buildQuery($parsed['query'])) : '');
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Form!FormBuilder.php/function/FormBuilder::buildFormAction/8.1.x