CreateHtmlRouteProvider.php in Entity API 8.0
File
src/Routing/CreateHtmlRouteProvider.php
View source
<?php
namespace Drupal\entity\Routing;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\EntityRouteProviderInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
class CreateHtmlRouteProvider implements EntityRouteProviderInterface {
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;
}
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;
}
}
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;
}
}
}