You are here

public function EntityDuplicateController::form in Entity API 8

Builds the duplicate form.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match.

Return value

array The rendered form.

File

src/Controller/EntityDuplicateController.php, line 80

Class

EntityDuplicateController

Namespace

Drupal\entity\Controller

Code

public function form(RouteMatchInterface $route_match) {
  $entity_type_id = $route_match
    ->getRouteObject()
    ->getDefault('entity_type_id');
  $source_entity = $route_match
    ->getParameter($entity_type_id);
  $entity = $source_entity
    ->createDuplicate();

  /** @var \Drupal\entity\Form\EntityDuplicateFormInterface $form_object */
  $form_object = $this->entityTypeManager
    ->getFormObject($entity_type_id, 'duplicate');
  $form_object
    ->setEntity($entity);
  $form_object
    ->setSourceEntity($source_entity);
  $form_state = new FormState();
  return $this->formBuilder
    ->buildForm($form_object, $form_state);
}