class UCWishlistController in UC Wish List 8
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\uc_wishlist\Controller\UCWishlistController
Expanded class hierarchy of UCWishlistController
File
- src/
Controller/ UCWishlistController.php, line 15
Namespace
Drupal\uc_wishlist\ControllerView source
class UCWishlistController extends ControllerBase {
/**
* @var \Drupal\uc_wishlist\Database\UcWishlistManager
*/
protected $wishlistManager;
/**
* Constructs a UCWishlistController object.
*
* @param \Drupal\uc_wishlist\Database\UcWishlistManager $wishlist_manager
*/
public function __construct(UcWishlistManager $wishlist_manager) {
$this->wishlistManager = $wishlist_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('uc_wishlist.manager'));
}
/**
* This function returns a list of user wish lists by displaying
* the user, title and expiration status.
*
* @return array
* a paged list of wish lists.
*/
public function AdminWishlist() {
$rows = [];
$header = [
[
'data' => t('User'),
'field' => 'u.name',
'sort' => 'asc',
],
[
'data' => t('Title'),
'field' => 'w.title',
],
[
'data' => t('Expiration date'),
'field' => 'w.expiration',
],
[
'data' => t('Status'),
],
];
// Database returns a paged list of wish lists.
$result = $this->db
->getAllWishlist();
foreach ($result as $wishlist) {
$deleteUrl = Url::fromRoute('uc_wishlist.admin_delete', [
'uc_wishlist' => $wishlist->wid,
]);
$link_options = [
'attributes' => [],
];
$deleteUrl
->setOptions($link_options);
// Wishlist expiration status.
$expired = '';
if ($wishlist->expiration < REQUEST_TIME) {
$expired = t('Expired');
}
elseif ($wishlist->expiration > 0) {
$expired = t('Active');
}
$deleteUrl = Link::fromTextAndUrl($expired . ' | Delete', $deleteUrl)
->toString();
$account = User::load($wishlist->uid);
$name = $account
->getAccountName();
$rows[] = [
$name ? Link::fromTextAndUrl($name, Url::fromRoute('entity.user.canonical', [
'user' => $wishlist->uid,
]))
->toString() : t('Anonymous'),
Link::fromTextAndUrl($wishlist->title, Url::fromRoute('uc_wishlist.wishlist_view', [
'wid' => $wishlist->wid,
]))
->toString(),
\Drupal::service('date.formatter')
->format($wishlist->expiration),
$deleteUrl,
];
}
if (empty($rows)) {
$rows[] = [
[
'data' => t('No wish lists found'),
'colspan' => 4,
],
];
}
return [
'#theme' => 'table',
'#header' => $header,
'#rows' => $rows,
];
}
/**
*
*/
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;
}
/**
*
*/
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;
}
/**
*
*/
public function userWishlist($user) {
return [];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 2 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
ControllerBase:: |
protected | function | Returns the state storage service. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UCWishlistController:: |
protected | property | ||
UCWishlistController:: |
public | function | This function returns a list of user wish lists by displaying the user, title and expiration status. | |
UCWishlistController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
UCWishlistController:: |
public | function | ||
UCWishlistController:: |
public | function | ||
UCWishlistController:: |
public | function | ||
UCWishlistController:: |
public | function | Constructs a UCWishlistController object. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |