You are here

function commerce_promotion_test_form_views_form_commerce_cart_form_default_alter in Commerce Core 8.2

Implements hook_form_BASE_FORM_ID_alter().

File

modules/promotion/tests/modules/commerce_promotion_test/commerce_promotion_test.module, line 14
Test module for Promotion.

Code

function commerce_promotion_test_form_views_form_commerce_cart_form_default_alter(&$form, FormStateInterface $form_state, $form_id) {

  // We know that view forms are build on the base ID plus arguments.
  $order_id = substr($form_id, strlen('views_form_commerce_cart_form_default_'));
  $inline_form_manager = \Drupal::getContainer()
    ->get('plugin.manager.commerce_inline_form');
  $inline_form = $inline_form_manager
    ->createInstance('coupon_redemption', [
    'order_id' => $order_id,
    'max_coupons' => Drupal::request()->query
      ->get('coupon_cardinality'),
  ]);

  // Workaround for core bug #2897377.
  $form['#id'] = Html::getId($form_state
    ->getBuildInfo()['form_id']);
  $form['coupons'] = [
    '#parents' => [
      'coupons',
    ],
  ];
  $form['coupons'] = $inline_form
    ->buildInlineForm($form['coupons'], $form_state);
}