public function ComponentRouteProvider::getRoutes in Module Builder 8.3
Provides routes for entities.
Parameters
\Drupal\Core\Entity\EntityTypeInterface $entity_type: The entity type
Return value
\Symfony\Component\Routing\RouteCollection|\Symfony\Component\Routing\Route[] Returns a route collection or an array of routes keyed by name, like route_callbacks inside 'routing.yml' files.
Overrides DefaultHtmlRouteProvider::getRoutes
File
- src/
Routing/ ComponentRouteProvider.php, line 20
Class
- ComponentRouteProvider
- Route provider for component entity types.
Namespace
Drupal\module_builder\RoutingCode
public function getRoutes(EntityTypeInterface $entity_type) {
$collection = parent::getRoutes($entity_type);
$entity_type_id = $entity_type
->id();
$admin_permission = $entity_type
->getAdminPermission();
$component_sections_handler = $this->entityTypeManager
->getHandler($entity_type_id, 'component_sections');
$section_route_data = $component_sections_handler
->getFormTabRoutePaths();
foreach ($section_route_data as $form_op => $title) {
$route = new Route($entity_type
->getLinkTemplate("{$form_op}-form"));
$route
->setDefaults([
'_entity_form' => "{$entity_type_id}.{$form_op}",
'_title_callback' => '\\Drupal\\module_builder\\Form\\ComponentSectionForm::title',
// We can't use an entity type parameter in the callback, as we want
// it to work with different entity types. So we specify the entity
// type as a parameter here, so the controller can use that to get the
// entity.
'entity_type' => $entity_type_id,
'title' => $title,
'op' => $form_op,
])
->setRequirement('_permission', $admin_permission)
->setOption('parameters', [
$entity_type_id => [
'type' => 'entity:' . $entity_type_id,
],
]);
$collection
->add("entity.{$entity_type_id}.{$form_op}_form", $route);
}
return $collection;
}