function EntityTypeManager::getFormObject

Creates a new form instance.

Parameters

string $entity_type_id: The entity type ID 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 205

Class

EntityTypeManager
Manages entity type plugin definitions.

Namespace

Drupal\Core\Entity

Code

public function getFormObject($entity_type_id, $operation) {
  if (!$class = $this->getDefinition($entity_type_id, TRUE)
    ->getFormClass($operation)) {
    $handlers = $this->getDefinition($entity_type_id, TRUE)
      ->getHandlerClasses();
    if (!isset($handlers['form'][$operation])) {
      throw new InvalidPluginDefinitionException($entity_type_id, sprintf('The "%s" entity type did not specify a "%s" form class.', $entity_type_id, $operation));
    }
    throw new InvalidPluginDefinitionException($entity_type_id, sprintf('The "%s" form handler of the "%s" entity type specifies a non-existent class "%s".', $operation, $entity_type_id, $handlers['form'][$operation]));
  }
  $form_object = $this->classResolver
    ->getInstanceFromDefinition($class);
  return $form_object->setStringTranslation($this->stringTranslation)
    ->setModuleHandler($this->moduleHandler)
    ->setEntityTypeManager($this)
    ->setOperation($operation);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.