class CreateHtmlRouteProvider in Entity API 8.0
Provides HTML routes for creating entities.
This class provides the following routes for entities, with title callbacks:
- add-page
- add-form
Hierarchy
- class \Drupal\entity\Routing\CreateHtmlRouteProvider implements EntityRouteProviderInterface
Expanded class hierarchy of CreateHtmlRouteProvider
See also
\Drupal\entity\Routing\AdminCreateHtmlRouteProvider.
File
- src/
Routing/ CreateHtmlRouteProvider.php, line 24 - Contains \Drupal\entity\Routing\CreateHtmlRouteProvider.
Namespace
Drupal\entity\RoutingView source
class CreateHtmlRouteProvider implements EntityRouteProviderInterface {
/**
* {@inheritdoc}
*/
public function getRoutes(EntityTypeInterface $entity_type) {
$routes = new RouteCollection();
if ($route = $this
->addPageRoute($entity_type)) {
$routes
->add('entity.' . $entity_type
->id() . '.add_page', $route);
}
if ($route = $this
->addFormRoute($entity_type)) {
$routes
->add('entity.' . $entity_type
->id() . '.add_form', $route);
}
return $routes;
}
/**
* Returns the add page route.
*
* Built only for entity types that have bundles.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function addPageRoute(EntityTypeInterface $entity_type) {
if ($entity_type
->hasLinkTemplate('add-page') && $entity_type
->getKey('bundle')) {
$route = new Route($entity_type
->getLinkTemplate('add-page'));
$route
->setDefault('_controller', '\\Drupal\\entity\\Controller\\EntityCreateController::addPage');
$route
->setDefault('_title_callback', '\\Drupal\\entity\\Controller\\EntityCreateController::addPageTitle');
$route
->setDefault('entity_type_id', $entity_type
->id());
$route
->setRequirement('_entity_create_access', $entity_type
->id());
return $route;
}
}
/**
* Returns the add form route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function addFormRoute(EntityTypeInterface $entity_type) {
if ($entity_type
->hasLinkTemplate('add-form')) {
$route = new Route($entity_type
->getLinkTemplate('add-form'));
$route
->setDefault('_controller', '\\Drupal\\entity\\Controller\\EntityCreateController::addForm');
$route
->setDefault('_title_callback', '\\Drupal\\entity\\Controller\\EntityCreateController::addFormTitle');
$route
->setDefault('entity_type_id', $entity_type
->id());
$route
->setRequirement('_entity_create_access', $entity_type
->id());
return $route;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CreateHtmlRouteProvider:: |
protected | function | Returns the add form route. | 1 |
CreateHtmlRouteProvider:: |
protected | function | Returns the add page route. | 1 |
CreateHtmlRouteProvider:: |
public | function |
Provides routes for entities. Overrides EntityRouteProviderInterface:: |