You are here

public function EntityFormModeBase::getForm in Form mode manager 8

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

This method are very similar to EntityFormBuilderInterface::getForm, for this module we need to add two form handler by form mode eg : form_mode_1 => EntityFormClass edit_form_mode_1 => EntityFormClass to provide ability to define different EntityForm class for form, for add/edit (or others) contexts. Actually EntityFormBuilderInterface::getForm are designed to only have, one operation (form mode) by action (add/edit/xxxx).

In that method we use $operation parameter to retrieve the correct, FormObject with our context prefixed by 'edit_' or not and in next step we, set the correct Operation form with only the form mode name, with ->setOperation() method onto FormObject.

Parameters

\Drupal\Core\Entity\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:.

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 entity Form.

2 calls to EntityFormModeBase::getForm()
EntityFormModeBase::entityEdit in src/Controller/EntityFormModeBase.php
Provides the entity 'edit' form.
UserFormModeController::entityEdit in src/Controller/UserFormModeController.php
Provides the entity 'edit' form.

File

src/Controller/EntityFormModeBase.php, line 272

Class

EntityFormModeBase
Controller for entity form mode support.

Namespace

Drupal\form_mode_manager\Controller

Code

public function getForm(EntityInterface $entity, $operation = 'default', array $form_state_additions = []) {
  $form_object = $this->entityTypeManager
    ->getFormObject($entity
    ->getEntityTypeId(), $operation);
  $form_object
    ->setEntity($entity)
    ->setOperation($this
    ->getFormModeOperationName($operation));
  $form_state = (new FormState())
    ->setFormState($form_state_additions);
  return $this->formBuilder
    ->buildForm($form_object, $form_state);
}