You are here

public function UCWishlistController::myWishlist in UC Wish List 8

1 string reference to 'UCWishlistController::myWishlist'
uc_wishlist.routing.yml in ./uc_wishlist.routing.yml
uc_wishlist.routing.yml

File

src/Controller/UCWishlistController.php, line 177

Class

UCWishlistController

Namespace

Drupal\uc_wishlist\Controller

Code

public function myWishlist() {

  // Setup our render array for all our page variables and configurations.
  $render = [];

  // Get the wishlist id based off of the current users id.
  $wid = uc_wishlist_get_wid();

  // Attempt to load the wish list.
  $wishlist = uc_wishlist_load($wid);
  $output = '';
  if (!$wishlist) {

    // Display a message letting them know their list is empty.
    $title = 'Wish list';
    drupal_set_message($this
      ->t("You have not added any products to your wish list. You can add any product from the store to your wish list by clicking the 'Add to wish list' button on the product's page."));
    $render['#markup'] = 'There are no products on this wish list.';
    $render['#title'] = $title;
    return $render;
  }
  $title = 'My Wish List';

  // Adding expiration info to display.
  if ($wishlist->expiration < REQUEST_TIME) {
    $output .= '<p>' . $this
      ->t('This wish list may no longer be valid. It was for an event on @date.', [
      '@date' => \Drupal::service('date.formatter')
        ->format($wishlist->expiration),
    ]) . '</p>';
  }
  elseif ($wishlist->expiration > 0) {
    $output .= '<p>' . $this
      ->t('This wish list is valid until @date.', [
      '@date' => \Drupal::service('date.formatter')
        ->format($wishlist->expiration),
    ]) . '</p>';
  }
  $items = uc_wishlist_get_contents($wid);
  if (empty($items)) {
    $render['#markup'] = '<p>There are no products in your wish list.</p>';
    return $render;
  }
  $form = \Drupal::formBuilder()
    ->getForm('Drupal\\uc_wishlist\\Form\\WishlistViewForm', $items, $wid, TRUE);
  $rendered_wishlistview_form = \Drupal::service('renderer')
    ->render($form);
  $render['#theme'] = 'uc_wishlist_view_wishlist';
  $render['#type'] = 'theme';
  $render['#title'] = $title;
  $render['#message'] = $output;
  $render['#form'] = $rendered_wishlistview_form;
  $render['#wishlist'] = $wishlist;
  return $render;
}