You are here

public function CartBlock::build in Commerce Cart Flyout 8

Builds and returns the renderable array for this block plugin.

If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).

Return value

array A renderable array representing the content of the block.

Overrides BlockPluginInterface::build

See also

\Drupal\block\BlockViewBuilder

File

src/Plugin/Block/CartBlock.php, line 109

Class

CartBlock
Provides a cart block.

Namespace

Drupal\commerce_cart_flyout\Plugin\Block

Code

public function build() {
  return [
    '#attached' => [
      'library' => [
        'commerce_cart_flyout/flyout',
      ],
      'drupalSettings' => [
        'cartFlyout' => [
          'use_quantity_count' => $this->configuration['use_quantity_count'],
          'templates' => [
            'icon' => $this
              ->renderTemplate('commerce_cart_flyout_block_icon'),
            'block' => $this
              ->renderTemplate('commerce_cart_flyout_block'),
            'offcanvas' => $this
              ->renderTemplate('commerce_cart_flyout_offcanvas'),
            'offcanvas_contents' => $this
              ->renderTemplate('commerce_cart_flyout_offcanvas_contents'),
            'offcanvas_contents_items' => $this
              ->renderTemplate('commerce_cart_flyout_offcanvas_contents_items'),
          ],
          'url' => Url::fromRoute('commerce_cart.page')
            ->toString(),
          'icon' => file_url_transform_relative(file_create_url(drupal_get_path('module', 'commerce') . '/icons/ffffff/cart.png')),
        ],
      ],
    ],
    '#markup' => Markup::create('<div class="cart-flyout"></div>'),
  ];
}