You are here

protected function SiteSettingEntityHtmlRouteProvider::getAddFormRoute in Site Settings and Labels 8

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

1 call to SiteSettingEntityHtmlRouteProvider::getAddFormRoute()
SiteSettingEntityHtmlRouteProvider::getRoutes in src/SiteSettingEntityHtmlRouteProvider.php
Provides routes for entities.

File

src/SiteSettingEntityHtmlRouteProvider.php, line 77

Class

SiteSettingEntityHtmlRouteProvider
Provides routes for Site Setting entities.

Namespace

Drupal\site_settings

Code

protected function getAddFormRoute(EntityTypeInterface $entity_type) {
  if ($entity_type
    ->hasLinkTemplate('add-form')) {
    $entity_type_id = $entity_type
      ->id();
    $parameters = [
      $entity_type_id => [
        'type' => 'entity:' . $entity_type_id,
      ],
    ];
    $route = new Route($entity_type
      ->getLinkTemplate('add-form'));
    $bundle_entity_type_id = $entity_type
      ->getBundleEntityType();

    // Content entities with bundles are added via a dedicated controller.
    $route
      ->setDefaults([
      '_controller' => 'Drupal\\site_settings\\Controller\\SiteSettingEntityAddController::addForm',
      '_title_callback' => 'Drupal\\site_settings\\Controller\\SiteSettingEntityAddController::getAddFormTitle',
    ])
      ->setRequirement('_entity_create_access', $entity_type_id . ':{' . $bundle_entity_type_id . '}');
    $parameters[$bundle_entity_type_id] = [
      'type' => 'entity:' . $bundle_entity_type_id,
    ];
    $route
      ->setOption('parameters', $parameters)
      ->setOption('_admin_route', TRUE);
    return $route;
  }
}