You are here

public function UserFormModeController::entityAdd in Form mode manager 8

Provides the entity submission form.

Parameters

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

Return value

array A User submission form.

Throws

\Exception If invalid entity type or form mode not exist.

Overrides EntityFormModeBase::entityAdd

File

src/Controller/UserFormModeController.php, line 29

Class

UserFormModeController
Controller for specific User entity form mode support.

Namespace

Drupal\form_mode_manager\Controller

Code

public function entityAdd(RouteMatchInterface $route_match) {

  /* @var \Drupal\Core\Entity\EntityInterface $entity */
  $entity = $this
    ->getEntityFromRouteMatch($route_match);
  if (empty($entity)) {
    $route_entity_type_info = $this
      ->getEntityTypeFromRouteMatch($route_match);

    /* @var \Drupal\Core\Entity\EntityInterface $entity */
    $entity = $this->entityTypeManager
      ->getStorage($route_entity_type_info['entity_type_id'])
      ->create([
      $route_entity_type_info['entity_key'] => $route_entity_type_info['bundle'],
    ]);
  }
  $form_mode_id = $this->formModeManager
    ->getFormModeMachineName($route_match
    ->getRouteObject()
    ->getOption('parameters')['form_mode']['id']);
  $operation = empty($form_mode_id) ? 'register' : $form_mode_id;
  if ($entity instanceof EntityInterface) {
    return $this->entityFormBuilder
      ->getForm($entity, $operation);
  }
}