You are here

public function FormBuilder::getForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Form/FormBuilder.php \Drupal\Core\Form\FormBuilder::getForm()

Gets a renderable form array.

This function should be used instead of self::buildForm() when $form_state is not needed (i.e., when initially rendering the form) and is often used as a menu callback.

Parameters

\Drupal\Core\Form\FormInterface|string $form_arg: The value must be one of the following:

...: Any additional arguments are passed on to the functions called by \Drupal::formBuilder()->getForm(), including the unique form constructor function. For example, the node_edit form requires that a node object is passed in here when it is called. These are available to implementations of hook_form_alter() and hook_form_FORM_ID_alter() as the array $form_state->getBuildInfo()['args'].

Return value

array The form array.

Overrides FormBuilderInterface::getForm

See also

\Drupal\Core\Form\FormBuilderInterface::buildForm()

File

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

Class

FormBuilder
Provides form building and processing.

Namespace

Drupal\Core\Form

Code

public function getForm($form_arg) {
  $form_state = new FormState();
  $args = func_get_args();

  // Remove $form_arg from the arguments.
  unset($args[0]);
  $form_state
    ->addBuildInfo('args', array_values($args));
  return $this
    ->buildForm($form_arg, $form_state);
}