function FormBuilder::getFormId
Same name in other branches
- 9 core/lib/Drupal/Core/Form/FormBuilder.php \Drupal\Core\Form\FormBuilder::getFormId()
- 8.9.x core/lib/Drupal/Core/Form/FormBuilder.php \Drupal\Core\Form\FormBuilder::getFormId()
- 11.x core/lib/Drupal/Core/Form/FormBuilder.php \Drupal\Core\Form\FormBuilder::getFormId()
2 calls to FormBuilder::getFormId()
- FormBuilder::buildForm in core/
lib/ Drupal/ Core/ Form/ FormBuilder.php - FormBuilder::submitForm in core/
lib/ Drupal/ Core/ Form/ FormBuilder.php
File
-
core/
lib/ Drupal/ Core/ Form/ FormBuilder.php, line 191
Class
- FormBuilder
- Provides form building and processing.
Namespace
Drupal\Core\FormCode
public function getFormId($form_arg, FormStateInterface &$form_state) {
// If the $form_arg is the name of a class, instantiate it. Don't allow
// arbitrary strings to be passed to the class resolver.
if (is_string($form_arg) && class_exists($form_arg)) {
$form_arg = $this->classResolver
->getInstanceFromDefinition($form_arg);
}
if (!is_object($form_arg)) {
throw new \InvalidArgumentException("The form class {$form_arg} could not be found or loaded.");
}
elseif (!$form_arg instanceof FormInterface) {
throw new \InvalidArgumentException('The form argument ' . $form_arg::class . ' must be an instance of \\Drupal\\Core\\Form\\FormInterface.');
}
// Add the $form_arg as the callback object and determine the form ID.
$form_state->setFormObject($form_arg);
if ($form_arg instanceof BaseFormIdInterface) {
$form_state->addBuildInfo('base_form_id', $form_arg->getBaseFormId());
}
return $form_arg->getFormId();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.