EntityFormBuilder.php
Same filename and directory in other branches
Namespace
Drupal\Core\EntityFile
-
core/
lib/ Drupal/ Core/ Entity/ EntityFormBuilder.php
View source
<?php
namespace Drupal\Core\Entity;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Form\FormState;
/**
* Builds entity forms.
*/
class EntityFormBuilder implements EntityFormBuilderInterface {
/**
* Constructs a new EntityFormBuilder.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager service.
* @param \Drupal\Core\Form\FormBuilderInterface $formBuilder
* The form builder.
*/
public function __construct(protected EntityTypeManagerInterface $entityTypeManager, protected FormBuilderInterface $formBuilder) {
}
/**
* {@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);
}
}
Classes
| Title | Deprecated | Summary |
|---|---|---|
| EntityFormBuilder | Builds entity forms. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.