class WishlistItemController in Commerce Wishlist 8.3
Provides the wishlist item pages.
Hierarchy
- class \Drupal\commerce_wishlist\Controller\WishlistItemController implements ContainerInjectionInterface uses StringTranslationTrait
Expanded class hierarchy of WishlistItemController
1 file declares its use of WishlistItemController
File
- src/
Controller/ WishlistItemController.php, line 19
Namespace
Drupal\commerce_wishlist\ControllerView source
class WishlistItemController implements ContainerInjectionInterface {
use StringTranslationTrait;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The form builder.
*
* @var \Drupal\Core\Form\FormBuilderInterface
*/
protected $formBuilder;
/**
* The route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* Constructs a new WishlistController object.
*
* @param \Drupal\Core\Session\AccountInterface $current_user
* The current user.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\Form\FormBuilderInterface $form_builder
* The form builder.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation.
*/
public function __construct(AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager, FormBuilderInterface $form_builder, RouteMatchInterface $route_match, TranslationInterface $string_translation) {
$this->currentUser = $current_user;
$this->entityTypeManager = $entity_type_manager;
$this->formBuilder = $form_builder;
$this->routeMatch = $route_match;
$this->stringTranslation = $string_translation;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('current_user'), $container
->get('entity_type.manager'), $container
->get('form_builder'), $container
->get('current_route_match'), $container
->get('string_translation'));
}
/**
* Builds the item details form.
*
* @return array
* The rendered form.
*/
public function detailsForm() {
$wishlist_item = $this->routeMatch
->getParameter('commerce_wishlist_item');
$form_object = $this->entityTypeManager
->getFormObject('commerce_wishlist_item', 'details');
$form_object
->setEntity($wishlist_item);
$form_state = new FormState();
return $this->formBuilder
->buildForm($form_object, $form_state);
}
/**
* Provides the title callback for the wishlist items collection route.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
*
* @return string
* The title.
*/
public function collectionTitle(RouteMatchInterface $route_match) {
$wishlist = $route_match
->getParameter('commerce_wishlist');
assert($wishlist instanceof WishlistInterface);
return $this
->t('%label items', [
'%label' => $wishlist
->label(),
]);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
WishlistItemController:: |
protected | property | The current user. | |
WishlistItemController:: |
protected | property | The entity type manager. | |
WishlistItemController:: |
protected | property | The form builder. | |
WishlistItemController:: |
protected | property | The route match. | |
WishlistItemController:: |
public | function | Provides the title callback for the wishlist items collection route. | |
WishlistItemController:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
WishlistItemController:: |
public | function | Builds the item details form. | |
WishlistItemController:: |
public | function | Constructs a new WishlistController object. |