class EntityFormBuilder in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/Entity/EntityFormBuilder.php \Drupal\Core\Entity\EntityFormBuilder
- 10 core/lib/Drupal/Core/Entity/EntityFormBuilder.php \Drupal\Core\Entity\EntityFormBuilder
Builds entity forms.
Hierarchy
- class \Drupal\Core\Entity\EntityFormBuilder implements EntityFormBuilderInterface
Expanded class hierarchy of EntityFormBuilder
1 file declares its use of EntityFormBuilder
- EntityFormBuilderTest.php in core/
tests/ Drupal/ Tests/ Core/ Entity/ EntityFormBuilderTest.php
1 string reference to 'EntityFormBuilder'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses EntityFormBuilder
File
- core/
lib/ Drupal/ Core/ Entity/ EntityFormBuilder.php, line 11
Namespace
Drupal\Core\EntityView source
class EntityFormBuilder implements EntityFormBuilderInterface {
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The form builder.
*
* @var \Drupal\Core\Form\FormBuilderInterface
*/
protected $formBuilder;
/**
* Constructs a new EntityFormBuilder.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
* The form builder.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, FormBuilderInterface $form_builder) {
$this->entityTypeManager = $entity_type_manager;
$this->formBuilder = $form_builder;
}
/**
* {@inheritdoc}
*/
public function getForm(EntityInterface $entity, $operation = 'default', array $form_state_additions = []) {
$form_object = $this->entityTypeManager
->getFormObject($entity
->getEntityTypeId(), $operation);
$form_object
->setEntity($entity);
$form_state = (new FormState())
->setFormState($form_state_additions);
return $this->formBuilder
->buildForm($form_object, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityFormBuilder:: |
protected | property | The entity type manager service. | |
EntityFormBuilder:: |
protected | property | The form builder. | |
EntityFormBuilder:: |
public | function |
Gets the built and processed entity form for the given entity. Overrides EntityFormBuilderInterface:: |
|
EntityFormBuilder:: |
public | function | Constructs a new EntityFormBuilder. |