function HtmlEntityFormController::getFormObject
Same name in other branches
- 9 core/lib/Drupal/Core/Entity/HtmlEntityFormController.php \Drupal\Core\Entity\HtmlEntityFormController::getFormObject()
- 8.9.x core/lib/Drupal/Core/Entity/HtmlEntityFormController.php \Drupal\Core\Entity\HtmlEntityFormController::getFormObject()
- 10 core/lib/Drupal/Core/Entity/HtmlEntityFormController.php \Drupal\Core\Entity\HtmlEntityFormController::getFormObject()
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:
path: '/foo/{node}/bar'
defaults:
_entity_form: 'node.edit'
This means that the edit form for the node entity will used. If the entity type has a default form, only the name of the entity {param} needs to be passed:
path: '/foo/{node}/baz'
defaults:
_entity_form: 'node'
Overrides FormController::getFormObject
File
-
core/
lib/ Drupal/ Core/ Entity/ HtmlEntityFormController.php, line 64
Class
- HtmlEntityFormController
- Wrapping controller for entity forms that serve as the main page body.
Namespace
Drupal\Core\EntityCode
protected function getFormObject(RouteMatchInterface $route_match, $form_arg) {
// If no operation is provided, use 'default'.
$form_arg .= '.default';
[
$entity_type_id,
$operation,
] = explode('.', $form_arg);
$form_object = $this->entityTypeManager
->getFormObject($entity_type_id, $operation);
// Allow the entity form to determine the entity object from a given route
// match.
$entity = $form_object->getEntityFromRouteMatch($route_match, $entity_type_id);
$form_object->setEntity($entity);
return $form_object;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.