protected function HtmlFormController::getFormObject

Returns the object used to build the form.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The request using this form.

string $form_arg: Either a class name or a service ID.

Return value

\Drupal\Core\Form\FormInterface The form object to use.

1 call to HtmlFormController::getFormObject()
HtmlFormController::content in drupal/core/lib/Drupal/Core/Controller/HtmlFormController.php
Controller method for generic HTML form pages.
1 method overrides HtmlFormController::getFormObject()
HtmlEntityFormController::getFormObject in drupal/core/lib/Drupal/Core/Entity/HtmlEntityFormController.php
Instead of a class name or service ID, $form_arg will be a string representing the entity and operation being performed. Consider the following route:

File

drupal/core/lib/Drupal/Core/Controller/HtmlFormController.php, line 80
Contains \Drupal\Core\Controller\HtmlFormController.

Class

HtmlFormController
Wrapping controller for forms that serve as the main page body.

Namespace

Drupal\Core\Controller

Code

protected function getFormObject(Request $request, $form_arg) {

  // If this is a class, instantiate it.
  if (class_exists($form_arg)) {
    if (in_array('Drupal\\Core\\Controller\\ControllerInterface', class_implements($form_arg))) {
      return $form_arg::create($this->container);
    }
    return new $form_arg();
  }

  // Otherwise, it is a service.
  return $this->container
    ->get($form_arg);
}