You are here

public function EntityTypeManager::getFormObject in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Entity/EntityTypeManager.php \Drupal\Core\Entity\EntityTypeManager::getFormObject()

Creates a new form instance.

Parameters

string $entity_type: The entity type for this form.

string $operation: The name of the operation to use, e.g., 'default'.

Return value

\Drupal\Core\Entity\EntityFormInterface A form instance.

Overrides EntityTypeManagerInterface::getFormObject

File

core/lib/Drupal/Core/Entity/EntityTypeManager.php, line 179
Contains \Drupal\Core\Entity\EntityTypeManager.

Class

EntityTypeManager
Manages entity type plugin definitions.

Namespace

Drupal\Core\Entity

Code

public function getFormObject($entity_type, $operation) {
  if (!isset($this->handlers['form'][$operation][$entity_type])) {
    if (!($class = $this
      ->getDefinition($entity_type, TRUE)
      ->getFormClass($operation))) {
      throw new InvalidPluginDefinitionException($entity_type, sprintf('The "%s" entity type did not specify a "%s" form class.', $entity_type, $operation));
    }
    $form_object = $this->classResolver
      ->getInstanceFromDefinition($class);
    $form_object
      ->setStringTranslation($this->stringTranslation)
      ->setModuleHandler($this->moduleHandler)
      ->setEntityTypeManager($this)
      ->setOperation($operation)
      ->setEntityManager(\Drupal::entityManager());
    $this->handlers['form'][$operation][$entity_type] = $form_object;
  }
  return $this->handlers['form'][$operation][$entity_type];
}