You are here

class WishlistRouteProvider in Commerce Wishlist 8.3

Provides routes for the wishlist entity.

Hierarchy

Expanded class hierarchy of WishlistRouteProvider

File

src/WishlistRouteProvider.php, line 14

Namespace

Drupal\commerce_wishlist
View source
class WishlistRouteProvider extends AdminHtmlRouteProvider {

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  protected function getCanonicalRoute(EntityTypeInterface $entity_type) {
    $route = new Route('/wishlist/{code}');
    $route
      ->addDefaults([
      '_controller' => WishlistController::class . '::userForm',
      '_title' => 'Wishlist',
    ])
      ->setRequirement('_access', 'TRUE');
    return $route;
  }

  /**
   * Gets the share-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 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;
  }

  /**
   * Gets the user-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 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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DefaultHtmlRouteProvider::$entityFieldManager protected property The entity field manager.
DefaultHtmlRouteProvider::$entityTypeManager protected property The entity type manager.
DefaultHtmlRouteProvider::createInstance public static function Instantiates a new instance of this entity handler. Overrides EntityHandlerInterface::createInstance 1
DefaultHtmlRouteProvider::getAddFormRoute protected function Gets the add-form route. 2
DefaultHtmlRouteProvider::getAddPageRoute protected function Gets the add page route. 2
DefaultHtmlRouteProvider::getCollectionRoute protected function Gets the collection route. Overrides DefaultHtmlRouteProvider::getCollectionRoute
DefaultHtmlRouteProvider::getDeleteFormRoute protected function Gets the delete-form route. 1
DefaultHtmlRouteProvider::getDeleteMultipleFormRoute protected function Returns the delete multiple form route. 1
DefaultHtmlRouteProvider::getDuplicateFormRoute protected function Gets the duplicate-form route.
DefaultHtmlRouteProvider::getEditFormRoute protected function Gets the edit-form route. 1
DefaultHtmlRouteProvider::getEntityTypeIdKeyType protected function Gets the type of the ID key for a given entity type. 1
DefaultHtmlRouteProvider::__construct public function Constructs a new DefaultHtmlRouteProvider. 1
WishlistRouteProvider::getCanonicalRoute protected function Gets the canonical route. Overrides DefaultHtmlRouteProvider::getCanonicalRoute
WishlistRouteProvider::getRoutes public function Provides routes for entities. Overrides AdminHtmlRouteProvider::getRoutes
WishlistRouteProvider::getShareFormRoute protected function Gets the share-form route.
WishlistRouteProvider::getUserFormRoute protected function Gets the user-form route.