You are here

public function AddToCartLink::build in Commerce Add To Cart Link 8

Same name and namespace in other branches
  1. 2.x src/AddToCartLink.php \Drupal\commerce_add_to_cart_link\AddToCartLink::build()

Generate a render array for an add-to-cart link.

Return value

array The render array.

File

src/AddToCartLink.php, line 56

Class

AddToCartLink
Defines a helper class for constructing add to cart links.

Namespace

Drupal\commerce_add_to_cart_link

Code

public function build() {
  $build = [
    '#theme' => 'commerce_add_to_cart_link',
    '#url' => $this
      ->url(),
    '#product_variation' => $this->variation,
  ];
  $metadata = $this
    ->metadata();
  $metadata
    ->applyTo($build);
  return $build;
}