You are here

interface CartLinkTokenInterface in Commerce Add To Cart Link 8

Same name and namespace in other branches
  1. 2.x src/CartLinkTokenInterface.php \Drupal\commerce_add_to_cart_link\CartLinkTokenInterface

Provides the cart link token interface.

This service is responsible for both generating and validating tokens that are added to the cart links. The tokens are tied to the user session.

Hierarchy

Expanded class hierarchy of CartLinkTokenInterface

All classes that implement CartLinkTokenInterface

2 files declare their use of CartLinkTokenInterface
AddToCartController.php in src/Controller/AddToCartController.php
AddToWishlistController.php in modules/wishlist/src/Controller/AddToWishlistController.php

File

src/CartLinkTokenInterface.php, line 14

Namespace

Drupal\commerce_add_to_cart_link
View source
interface CartLinkTokenInterface {

  /**
   * Generates a token for the given product variation.
   *
   * The token is added to the add to cart link and tied to the user session.
   *
   * @param \Drupal\commerce_product\Entity\ProductVariationInterface $variation
   *   The product variation.
   *
   * @return string
   *   The generated token.
   */
  public function generate(ProductVariationInterface $variation);

  /**
   * Checks the given token for the given variation for validity.
   *
   * @param \Drupal\commerce_product\Entity\ProductVariationInterface $variation
   *   The product variation.
   * @param string $token
   *   The token to be validated.
   *
   * @return bool
   *   TRUE, if the given token is valid, FALSE otherwise.
   */
  public function validate(ProductVariationInterface $variation, $token);

  /**
   * Checks whether the given user account needs CSRF protection.
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   *   The user account. If left NULL, the current user will be taken.
   * @return bool
   *   TRUE, if add to cart and wishlist links should be CSRF protected, FALSE
   *   otherwise.
   */
  public function needsCsrfProtection(AccountInterface $account = NULL);

}

Members

Namesort descending Modifiers Type Description Overrides
CartLinkTokenInterface::generate public function Generates a token for the given product variation. 1
CartLinkTokenInterface::needsCsrfProtection public function Checks whether the given user account needs CSRF protection. 1
CartLinkTokenInterface::validate public function Checks the given token for the given variation for validity. 1