function commerce_cart_blocks_form_commerce_order_type_form_alter in Commerce Cart Blocks 8
Implements hook_form_BASE_FORM_ID_alter().
File
- ./
commerce_cart_blocks.module, line 49 - Contains commerce_cart_blocks.module.
Code
function commerce_cart_blocks_form_commerce_order_type_form_alter(&$form, FormStateInterface $form_state, $form_id) {
/** @var \Drupal\commerce_order\Entity\OrderTypeInterface $order_type */
$order_type = $form_state
->getFormObject()
->getEntity();
$form['commerce_cart_blocks'] = [
'#type' => 'details',
'#title' => t('Commerce Cart Blocks'),
'#description' => t('Additional options when using Commerce Cart Blocks.'),
'#weight' => 5,
'#open' => TRUE,
'#collapsible' => TRUE,
];
$form['commerce_cart_blocks']['commerce_cart_blocks_ajax'] = [
'#type' => 'checkbox',
'#title' => t('Enable AJAX for Commerce Cart Blocks'),
'#weight' => 0,
'#default_value' => $order_type
->getThirdPartySetting('commerce_cart_blocks', 'commerce_cart_blocks_ajax', FALSE),
];
$form['commerce_cart_blocks']['commerce_cart_blocks_ajax_modal'] = [
'#type' => 'checkbox',
'#title' => t('Show a modal window after adding an item to the cart with AJAX'),
'#weight' => 1,
'#default_value' => $order_type
->getThirdPartySetting('commerce_cart_blocks', 'commerce_cart_blocks_ajax_modal', TRUE),
'#states' => [
'visible' => [
':input[name="commerce_cart_blocks[commerce_cart_blocks_ajax]"]' => [
'checked' => TRUE,
],
],
],
];
$form['commerce_cart_blocks']['commerce_cart_blocks_refresh_page_after_modal'] = [
'#type' => 'checkbox',
'#title' => t('Refresh the page when closing the modal window'),
'#weight' => 2,
'#default_value' => $order_type
->getThirdPartySetting('commerce_cart_blocks', 'commerce_cart_blocks_refresh_page_after_modal', FALSE),
'#states' => [
'visible' => [
':input[name="commerce_cart_blocks[commerce_cart_blocks_ajax_modal]"]' => [
'checked' => TRUE,
],
],
],
];
$form['commerce_cart_blocks']['commerce_cart_blocks_links'] = [
'#type' => 'details',
'#title' => t('Add links to modal'),
'#description' => t('You can optionally add buttons to the modal window that link to the cart, checkout, or back to the current page.'),
'#weight' => 3,
'#open' => TRUE,
'#collapsible' => TRUE,
'#states' => [
'visible' => [
':input[name="commerce_cart_blocks[commerce_cart_blocks_ajax]"]' => [
'checked' => TRUE,
],
],
],
];
$form['commerce_cart_blocks']['commerce_cart_blocks_links']['commerce_cart_blocks_add_cart'] = [
'#type' => 'checkbox',
'#title' => t('Show View Cart link in modal'),
'#weight' => 0,
'#default_value' => $order_type
->getThirdPartySetting('commerce_cart_blocks', 'commerce_cart_blocks_add_cart', TRUE),
'#states' => [
'visible' => [
':input[name="commerce_cart_blocks[commerce_cart_blocks_ajax]"]' => [
'checked' => TRUE,
],
],
],
];
$form['commerce_cart_blocks']['commerce_cart_blocks_links']['commerce_cart_blocks_add_checkout'] = [
'#type' => 'checkbox',
'#title' => t('Show Checkout link in modal'),
'#weight' => 1,
'#default_value' => $order_type
->getThirdPartySetting('commerce_cart_blocks', 'commerce_cart_blocks_add_checkout', TRUE),
'#states' => [
'visible' => [
':input[name="commerce_cart_blocks[commerce_cart_blocks_ajax]"]' => [
'checked' => TRUE,
],
],
],
];
$form['commerce_cart_blocks']['commerce_cart_blocks_links']['commerce_cart_blocks_add_keep_browsing'] = [
'#type' => 'checkbox',
'#title' => t('Show Keep Browsing link in modal'),
'#weight' => 2,
'#default_value' => $order_type
->getThirdPartySetting('commerce_cart_blocks', 'commerce_cart_blocks_add_keep_browsing', TRUE),
'#states' => [
'visible' => [
':input[name="commerce_cart_blocks[commerce_cart_blocks_ajax]"]' => [
'checked' => TRUE,
],
],
],
];
$form['commerce_cart_blocks']['commerce_cart_blocks_ajax_modal_title'] = [
'#type' => 'textfield',
'#title' => 'Title of the cart modal',
'#weight' => 4,
'#default_value' => $order_type
->getThirdPartySetting('commerce_cart_blocks', 'commerce_cart_blocks_ajax_modal_title', 'Cart'),
'#states' => [
'visible' => [
':input[name="commerce_cart_blocks[commerce_cart_blocks_ajax]"]' => [
'checked' => TRUE,
],
],
],
];
$form['commerce_cart_blocks']['commerce_cart_blocks_append_block_id'] = [
'#type' => 'textfield',
'#title' => t('Block id to append cart to block'),
'#weight' => 5,
'#description' => t('Enter the block id the cart block immediately follows to append when entering the first cart item.'),
'#default_value' => $order_type
->getThirdPartySetting('commerce_cart_blocks', 'commerce_cart_blocks_append_block_id', ''),
'#states' => [
'visible' => [
':input[name="commerce_cart_blocks[commerce_cart_blocks_ajax]"]' => [
'checked' => TRUE,
],
],
],
];
$form['actions']['submit']['#submit'][] = 'commerce_cart_blocks_order_type_form_submit';
}