You are here

public function FlexiformManager::getFormObject in Flexiform 8

Get a form object from an entity form display.

Parameters

\Drupal\flexiform\FlexiformEntityFormDisplayInterface $form_display: The form display.

\Drupal\Core\Entity\EntityInterface[] $provided_entities: The entities provided by for form.

Return value

\Drupal\Core\Form\FormInterface The form object.

File

src/FlexiformManager.php, line 78

Class

FlexiformManager
Provides the Flexiform manager.

Namespace

Drupal\flexiform

Code

public function getFormObject(FlexiformEntityFormDisplayInterface $form_display, array $provided_entities = []) {
  if ($entity_type_id = $form_display
    ->getTargetEntityTypeId()) {
    $bundle = $form_display
      ->getTargetBundle();
    $mode = $form_display
      ->getMode();
    $entity_type = $this->entityTypeManager
      ->getDefinition($entity_type_id);

    // @todo: Consider how best to behaver here. Do we fall back to default?
    // Or ContentEntityForm?
    $class = $entity_type
      ->getFormClass($mode);
    if (!$class) {
      $class = $entity_type
        ->getFormClass('default');
    }
    if (!$class) {
      $class = '\\Drupal\\Core\\Entity\\ContentEntityForm';
    }
    $form_object = $this->classResolver
      ->getInstanceFromDefinition($class);
    $form_object
      ->setStringTranslation($this->stringTranslation)
      ->setModuleHandler($this->moduleHandler)
      ->setEntityTypeManager($this->entityTypeManager)
      ->setOperation($mode)
      ->setEntityManager(\Drupal::entityManager());
    if (!empty($provided_entities[$form_display
      ->getBaseEntityNamespace()])) {
      $form_object
        ->setEntity($provided_entities[$form_display
        ->getBaseEntityNamespace()]);
    }
    return $form_object;
  }
  else {
  }
}