You are here

public function FormController::getContentResult in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 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 62
Contains \Drupal\Core\Controller\FormController.

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->controllerResolver
    ->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);
}