commercetools-8.x-1.2-alpha1/modules/commercetools_content/commercetools_content.module
modules/commercetools_content/commercetools_content.module
<?php
/**
* @file
* Defines the commercetools_content module hooks.
*/
use Drupal\Core\Block\BlockPluginInterface;
use Drupal\commercetools_content\Service\CommercetoolsAjaxHelper;
/**
* Implements hook_block_view_alter().
*
* Dynamically adds AJAX attributes to blocks that support AJAX loading.
*/
function commercetools_content_block_view_alter(array &$build, BlockPluginInterface $block) {
$controllerUseAjax = FALSE;
if ($block->getPluginId() == CommercetoolsAjaxHelper::SYSTEM_BLOCK_PLUGIN_ID) {
$ajaxHelper = \Drupal::service('commercetools_content.ajax_helper');
$controllerUseAjax = $ajaxHelper->isSystemBlockAjaxified();
// Mark system main blocks for easier identification in JS.
$build['#attributes'][CommercetoolsAjaxHelper::COMMERCETOOLS_SYSTEM_BLOCK_ATTRIBUTE] = 1;
// Save block id.
$build['#attributes'][CommercetoolsAjaxHelper::COMMERCETOOLS_BLOCK_ID] = $build['#id'];
}
if ($controllerUseAjax ||
isset($block->getConfiguration()['use_ajax'])) {
CommercetoolsAjaxHelper::applyAjaxifyAttributesToBlock($build, $block->getConfiguration()['product_list_index'] ?? 0);
}
}
/**
* Implements hook_theme().
*/
function commercetools_content_theme() {
return [
'commercetools_product_cards' => [
'variables' => [
'list' => NULL,
'pager' => NULL,
'no_products_found' => FALSE,
'items' => [],
'columns_number' => [],
],
],
'commercetools_product_list' => [
'variables' => [
'list' => NULL,
'pager' => NULL,
'no_products_found' => FALSE,
'items' => [],
'columns_number' => [],
],
],
'commercetools_product_titles' => [
'variables' => [
'list' => NULL,
'pager' => NULL,
'no_products_found' => FALSE,
'items' => [],
],
],
'commercetools_product_cards_item' => [
'render element' => 'elements',
'variables' => [
'product' => NULL,
'url' => NULL,
'attributes' => NULL,
'unavailable_data_text' => NULL,
],
],
'commercetools_product_list_item' => [
'render element' => 'elements',
'variables' => [
'product' => NULL,
'url' => NULL,
'attributes' => NULL,
'unavailable_data_text' => NULL,
],
],
'commercetools_product_titles_item' => [
'render element' => 'elements',
'variables' => [
'product' => NULL,
'url' => NULL,
],
],
'commercetools_product_page' => [
'render element' => 'elements',
'variables' => [
'product' => NULL,
'add_to_cart' => NULL,
'attributes' => NULL,
'product_attributes' => NULL,
'unavailable_data_text' => NULL,
],
],
'commercetools_carousel' => [
'variables' => [
'selector' => NULL,
'items' => [],
'activeSlide' => 0,
],
],
'commercetools_gallery_modal' => [
'variables' => [
'selector' => NULL,
'title' => NULL,
'content' => NULL,
],
],
'commercetools_product_attribute' => [
'variables' => [
'attribute' => [],
'label' => NULL,
'value' => NULL,
],
],
'commercetools_product_attribute_label' => [
'variables' => [
'label' => NULL,
'key' => NULL,
],
],
'commercetools_product_attribute_form_element' => [
'render element' => 'element',
'base hook' => 'form_element',
],
'commercetools_add_to_cart_form' => [
'render element' => 'form',
],
'commercetools_cart_form' => [
'render element' => 'form',
],
'commercetools_line_items' => [
'variables' => [
'lineItems' => [],
'lineStyle' => 'default',
],
],
'commercetools_order_page' => [
'variables' => [
'attributes' => [],
'order' => NULL,
],
],
'commercetools_order_card' => [
'variables' => [
'attributes' => [],
'order' => NULL,
],
],
'commercetools_cart_summary_block' => [
'variables' => [
'cart' => NULL,
'max_items' => NULL,
],
],
'commercetools_filter_label' => [
'variables' => [
'label' => NULL,
],
],
'commercetools_filter_option' => [
'variables' => [
'label' => NULL,
'count' => NULL,
'key' => NULL,
],
],
'commercetools_categories_cards_block' => [
'variables' => [
'items' => [],
'cards_columns' => NULL,
],
],
];
}
