protected function HtmlEntityFormController::getFormObject

Instead of a class name or service ID, $form_arg will be a string representing the entity and operation being performed. Consider the following route:


  pattern: '/foo/{node}/bar'
  defaults:
    _entity_form: 'node.edit'

This means that the edit form controller for the node entity will used. If the entity type has a default form controller, only the name of the entity {param} needs to be passed:


  pattern: '/foo/{node}/baz'
  defaults:
    _entity_form: 'node'

Overrides HtmlFormController::getFormObject

File

drupal/core/lib/Drupal/Core/Entity/HtmlEntityFormController.php, line 48
Contains \Drupal\Core\Entity\HtmlEntityFormController.

Class

HtmlEntityFormController
Wrapping controller for entity forms that serve as the main page body.

Namespace

Drupal\Core\Entity

Code

protected function getFormObject(Request $request, $form_arg) {
  $manager = $this->container
    ->get('plugin.manager.entity');

  // If no operation is provided, use 'default'.
  $form_arg .= '.default';
  list($entity_type, $operation) = explode('.', $form_arg);
  if ($request->attributes
    ->has($entity_type)) {
    $entity = $request->attributes
      ->get($entity_type);
  }
  else {
    $entity = $manager
      ->getStorageController($entity_type)
      ->create(array());
  }
  return $manager
    ->getFormController($entity_type, $operation)
    ->setEntity($entity);
}