function EntityTypeManager::getFormObject

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/EntityTypeManager.php \Drupal\Core\Entity\EntityTypeManager::getFormObject()
  2. 8.9.x core/lib/Drupal/Core/Entity/EntityTypeManager.php \Drupal\Core\Entity\EntityTypeManager::getFormObject()
  3. 11.x core/lib/Drupal/Core/Entity/EntityTypeManager.php \Drupal\Core\Entity\EntityTypeManager::getFormObject()

File

core/lib/Drupal/Core/Entity/EntityTypeManager.php, line 208

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.