You are here

public function CartLinkToken::generate in Commerce Add To Cart Link 2.x

Same name and namespace in other branches
  1. 8 src/CartLinkToken.php \Drupal\commerce_add_to_cart_link\CartLinkToken::generate()

Generates a token for the given product variation.

The token is added to the add to cart link.

Parameters

\Drupal\commerce_product\Entity\ProductVariationInterface $variation: The product variation.

Return value

string The generated token.

Overrides CartLinkTokenInterface::generate

1 call to CartLinkToken::generate()
CartLinkToken::validate in src/CartLinkToken.php
Checks the given token for the given variation for validity.

File

src/CartLinkToken.php, line 57

Class

CartLinkToken
Default cart link token service implementation.

Namespace

Drupal\commerce_add_to_cart_link

Code

public function generate(ProductVariationInterface $variation) {
  if (!$this
    ->needsCsrfProtection($this->currentUser)) {
    return '';
  }
  $value = $this
    ->generateTokenValue($variation);
  return substr(Crypt::hmacBase64($value, $this->privateKey
    ->get() . $this
    ->getHashSalt()), 0, 16);
}