function FormBuilder::buildFormAction

Same name in other branches
  1. 9 core/lib/Drupal/Core/Form/FormBuilder.php \Drupal\Core\Form\FormBuilder::buildFormAction()
  2. 10 core/lib/Drupal/Core/Form/FormBuilder.php \Drupal\Core\Form\FormBuilder::buildFormAction()
  3. 11.x 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'].

1 call to FormBuilder::buildFormAction()
FormBuilder::renderPlaceholderFormAction in core/lib/Drupal/Core/Form/FormBuilder.php
Renders a form action URL. It's a #lazy_builder callback.

File

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

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]);
    $action = $parsed['path'] . ($parsed['query'] ? '?' . UrlHelper::buildQuery($parsed['query']) : '');
    return UrlHelper::filterBadProtocol($action);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.