You are here

public function WishlistController::wishlistPage in Commerce Wishlist 8.3

Builds the wishlist page.

If the customer doesn't have a wishlist, or the wishlist is empty, the "empty page" will be shown. Otherwise, the customer will be redirected to the default wishlist.

Return value

array|\Symfony\Component\HttpFoundation\RedirectResponse A render array, or a redirect response.

1 string reference to 'WishlistController::wishlistPage'
commerce_wishlist.routing.yml in ./commerce_wishlist.routing.yml
commerce_wishlist.routing.yml

File

src/Controller/WishlistController.php, line 113

Class

WishlistController
Provides the wishlist pages.

Namespace

Drupal\commerce_wishlist\Controller

Code

public function wishlistPage() {
  $wishlist = $this->wishlistProvider
    ->getWishlist($this
    ->getDefaultWishlistType());
  if (!$wishlist || !$wishlist
    ->hasItems()) {
    return [
      '#theme' => 'commerce_wishlist_empty_page',
    ];
  }

  // Authenticated users should always manage wishlists via the user form.
  $rel = $this->currentUser
    ->isAuthenticated() ? 'user-form' : 'canonical';
  $url = $wishlist
    ->toUrl($rel, [
    'absolute' => TRUE,
  ]);
  return new RedirectResponse($url
    ->toString());
}