public function EntityTypeManager::getFormObject

public EntityTypeManager::getFormObject($entity_type, $operation)

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 174

Class

EntityTypeManager
Manages entity type plugin definitions.

Namespace

Drupal\Core\Entity

Code

public function getFormObject($entity_type, $operation) {
  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);

  return $form_object
  ->setStringTranslation($this->stringTranslation)
    ->setModuleHandler($this->moduleHandler)
    ->setEntityTypeManager($this)
    ->setOperation($operation)
    // The entity manager cannot be injected due to a circular dependency.
    // @todo Remove this set call in https://www.drupal.org/node/2603542.
    ->setEntityManager(\Drupal::entityManager());
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!EntityTypeManager.php/function/EntityTypeManager::getFormObject/8.1.x