class EntityFormBuilder implements EntityFormBuilderInterface (View source)

Builds entity forms.

Properties

protected EntityTypeManagerInterface $entityTypeManager

The entity type manager service.

protected FormBuilderInterface $formBuilder

The form builder.

Methods

__construct(EntityTypeManagerInterface $entity_type_manager, FormBuilderInterface $form_builder)

Constructs a new EntityFormBuilder.

array
getForm(EntityInterface $entity, string $operation = 'default', array $form_state_additions = [])

Gets the built and processed entity form for the given entity.

Details

__construct(EntityTypeManagerInterface $entity_type_manager, FormBuilderInterface $form_builder)

Constructs a new EntityFormBuilder.

Parameters

EntityTypeManagerInterface $entity_type_manager

The entity type manager service.

FormBuilderInterface $form_builder

The form builder.

array getForm(EntityInterface $entity, string $operation = 'default', array $form_state_additions = [])

Gets the built and processed entity form for the given entity.

The form may also be retrieved from the cache if the form was built in a previous page load. The form is then passed on for processing, validation, and submission if there is proper input.

Parameters

EntityInterface $entity

The entity to be created or edited.

string $operation

(optional) The operation identifying the form variation to be returned. Defaults to 'default'. This is typically used in routing: @code _entity_form: node.book_outline @endcode where "book_outline" is the value of $operation. The class name for the form for each operation (edit, delete, etc.) can be found in the form section of the handlers entity annotation. For example: @code handlers = { "form" = { "delete" = "Drupal\node\Form\NodeDeleteForm", @endcode Alternatively, the form class can be set from hook_entity_type_build().

array $form_state_additions

(optional) An associative array used to build the current state of the form. Use this to pass additional information to the form, such as the langcode. Defaults to an empty array.

Return Value

array

The processed form for the given entity and operation.