You are here

protected function CartBlockBase::buildLinks in Commerce Cart Blocks 8

2 calls to CartBlockBase::buildLinks()
CartBlock::build in src/Plugin/Block/CartBlock.php
Builds the cart block.
CartButtonBlock::build in src/Plugin/Block/CartButtonBlock.php
Builds the cart block.

File

src/Plugin/Block/CartBlockBase.php, line 180

Class

CartBlockBase
CartBlockBase class.

Namespace

Drupal\commerce_cart_blocks\Plugin\Block

Code

protected function buildLinks() {
  $links = [];
  $displayLinks = $this->configuration['display_links'];
  if ($displayLinks['checkout']) {
    $carts = $this
      ->getCarts();
    if (!empty($carts)) {

      /** @var \Drupal\commerce_order\Entity\OrderInterface $cart */
      $cart = array_shift($carts);
      $links[] = [
        '#type' => 'link',
        '#title' => $this->configuration['checkout_link_text'],
        '#url' => Url::fromRoute('commerce_checkout.form', [
          'commerce_order' => $cart
            ->id(),
        ]),
      ];
    }
  }
  if ($displayLinks['cart']) {
    $links[] = [
      '#type' => 'link',
      '#title' => $this->configuration['cart_link_text'],
      '#url' => Url::fromRoute('commerce_cart.page'),
    ];
  }
  return $links;
}