public function UCWishlistController::viewWishlist in UC Wish List 8
1 string reference to 'UCWishlistController::viewWishlist'
File
- src/
Controller/ UCWishlistController.php, line 115
Class
Namespace
Drupal\uc_wishlist\ControllerCode
public function viewWishlist($wid = NULL) {
$render = [];
$output = '';
$title = '';
$wishlist = NULL;
$rendered_wishlistview_form = '';
$own = FALSE;
if (!$own && $wid == uc_wishlist_get_wid()) {
return $this
->redirect('uc_wishlist.wishlist');
}
// Load the wish list.
$wishlist = uc_wishlist_load($wid);
// Handle a non-existent wish list.
if (!$wishlist) {
// Otherwise send them to the search form.
drupal_set_message($this
->t('The wish list you requested could not be found. Perhaps you can try looking for it through the wish list search form below.'));
return $this
->redirect('uc_wishlist.wishlist.search');
}
// Display only if the users wishlist is not set to private.
if (!$wishlist->private) {
// Set the title to the wishlist title.
$title = $wishlist->title;
// 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)) {
// @TODO: add the users name to the output string
$output = '<p>There are no products in this wish list.</p>';
// Return $render;.
}
else {
$form = \Drupal::formBuilder()
->getForm('Drupal\\uc_wishlist\\Form\\WishlistViewForm', $items, $wid, FALSE);
$rendered_wishlistview_form = \Drupal::service('renderer')
->render($form);
}
}
else {
drupal_set_message($this
->t('This users wish list is set to private. You may search for another user\'s wish list below.'));
return $this
->redirect('uc_wishlist.wishlist.search');
}
$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;
}