You are here

class WishlistItemController in Commerce Wishlist 8.3

Provides the wishlist item pages.

Hierarchy

Expanded class hierarchy of WishlistItemController

1 file declares its use of WishlistItemController
WishlistItemRouteProvider.php in src/WishlistItemRouteProvider.php

File

src/Controller/WishlistItemController.php, line 19

Namespace

Drupal\commerce_wishlist\Controller
View 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

Namesort descending Modifiers Type Description Overrides
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
WishlistItemController::$currentUser protected property The current user.
WishlistItemController::$entityTypeManager protected property The entity type manager.
WishlistItemController::$formBuilder protected property The form builder.
WishlistItemController::$routeMatch protected property The route match.
WishlistItemController::collectionTitle public function Provides the title callback for the wishlist items collection route.
WishlistItemController::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
WishlistItemController::detailsForm public function Builds the item details form.
WishlistItemController::__construct public function Constructs a new WishlistController object.