You are here

protected function CiviCrmEntityRouteProvider::getAddFormRoute in CiviCRM Entity 8.3

Gets the add-form route.

Parameters

\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type.

Return value

\Symfony\Component\Routing\Route|null The generated route, if available.

Overrides AdminHtmlRouteProvider::getAddFormRoute

File

src/Routing/CiviCrmEntityRouteProvider.php, line 28

Class

CiviCrmEntityRouteProvider
Provides routing for CiviCRM entities.

Namespace

Drupal\civicrm_entity\Routing

Code

protected function getAddFormRoute(EntityTypeInterface $entity_type) {
  $has_bundles = $entity_type
    ->hasKey('bundle');
  $entity_add_form_route = parent::getAddFormRoute($entity_type);
  if ($has_bundles) {

    // This ensures the form receives a default bundle from the
    // CivicrmEntity::preCreate method, avoiding the need for the `add_page`
    // route for selecting a bundle.
    assert($entity_add_form_route !== NULL);
    $entity_add_form_route
      ->setDefault('bundle', $entity_type
      ->id());
  }
  return $entity_add_form_route;
}