function FormController::getContentResult

Same name in other branches
  1. 9 core/lib/Drupal/Core/Controller/FormController.php \Drupal\Core\Controller\FormController::getContentResult()
  2. 10 core/lib/Drupal/Core/Controller/FormController.php \Drupal\Core\Controller\FormController::getContentResult()
  3. 11.x core/lib/Drupal/Core/Controller/FormController.php \Drupal\Core\Controller\FormController::getContentResult()

Invokes the form and returns the result.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request object.

\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match.

Return value

array The render array that results from invoking the controller.

File

core/lib/Drupal/Core/Controller/FormController.php, line 74

Class

FormController
Common base class for form interstitial controllers.

Namespace

Drupal\Core\Controller

Code

public function getContentResult(Request $request, RouteMatchInterface $route_match) {
    $form_arg = $this->getFormArgument($route_match);
    $form_object = $this->getFormObject($route_match, $form_arg);
    // Add the form and form_state to trick the getArguments method of the
    // controller resolver.
    $form_state = new FormState();
    $request->attributes
        ->set('form', []);
    $request->attributes
        ->set('form_state', $form_state);
    $args = $this->argumentResolver
        ->getArguments($request, [
        $form_object,
        'buildForm',
    ]);
    $request->attributes
        ->remove('form');
    $request->attributes
        ->remove('form_state');
    // Remove $form and $form_state from the arguments, and re-index them.
    unset($args[0], $args[1]);
    $form_state->addBuildInfo('args', array_values($args));
    return $this->formBuilder
        ->buildForm($form_object, $form_state);
}

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