WishlistRouteProvider.php in Commerce Wishlist 8.3
File
src/WishlistRouteProvider.php
View source
<?php
namespace Drupal\commerce_wishlist;
use Drupal\commerce_wishlist\Access\WishlistUserAccessCheck;
use Drupal\commerce_wishlist\Controller\WishlistController;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\entity\Routing\AdminHtmlRouteProvider;
use Symfony\Component\Routing\Route;
class WishlistRouteProvider extends AdminHtmlRouteProvider {
public function getRoutes(EntityTypeInterface $entity_type) {
$collection = parent::getRoutes($entity_type);
if ($share_form_route = $this
->getShareFormRoute($entity_type)) {
$collection
->add('entity.commerce_wishlist.share_form', $share_form_route);
}
if ($user_form_route = $this
->getUserFormRoute($entity_type)) {
$collection
->add('entity.commerce_wishlist.user_form', $user_form_route);
}
return $collection;
}
protected function getCanonicalRoute(EntityTypeInterface $entity_type) {
$route = new Route('/wishlist/{code}');
$route
->addDefaults([
'_controller' => WishlistController::class . '::userForm',
'_title' => 'Wishlist',
])
->setRequirement('_access', 'TRUE');
return $route;
}
protected function getShareFormRoute(EntityTypeInterface $entity_type) {
$route = new Route($entity_type
->getLinkTemplate('share-form'));
$route
->addDefaults([
'_controller' => WishlistController::class . '::shareForm',
'_title' => 'Wishlist',
])
->setRequirement('_custom_access', WishlistUserAccessCheck::class . '::checkAccess')
->setOption('parameters', [
'user' => [
'type' => 'entity:user',
],
]);
return $route;
}
protected function getUserFormRoute(EntityTypeInterface $entity_type) {
$route = new Route($entity_type
->getLinkTemplate('user-form'));
$route
->addDefaults([
'_controller' => WishlistController::class . '::userForm',
'_title' => 'Wishlist',
])
->setRequirement('_custom_access', WishlistUserAccessCheck::class . '::checkAccess')
->setOption('parameters', [
'user' => [
'type' => 'entity:user',
],
]);
return $route;
}
}