I am trying to create a new payment method and add JavaScript files in the Payment method callback: redirect form. However JavaScript files are not loaded at all.

Here is my implementation:

function mymodule_redirect_form($form, &$form_state, $order, $payment_method) {
  $form['#attached']['js'][] = drupal_get_path('module', 'mymodule') . 'file.js';

  $form['#attached']['js'][] = drupal_get_path('module', 'mymodule') . 'file2.js';
  ...

  return $form;
}

After digging the code I have found the problem:

function commerce_payment_redirect_pane_checkout_form(&$form, &$form_state, $checkout_pane, $order) {
  ...
  $form += drupal_get_form($callback, $order, $payment_method);
  ...  
}

As commerce_checkout.js is already added in '#attached' array, += will not append new JavaScript from mymodule_redirect_form.

To fix it, I think we can use drupal_array_merge_deep

  $form = drupal_array_merge_deep($form, drupal_get_form($callback, $order, $payment_method));
CommentFileSizeAuthor
#2 redirect_form_merge-2536720-2.patch826 byteseric.chenchao

Comments

eric.chenchao’s picture

Issue summary: View changes
eric.chenchao’s picture

Status: Active » Needs review
StatusFileSize
new826 bytes

Patch attached.

eric.chenchao’s picture

Title: redirect form in check-out pane not fully merged cause JavaScript not loading » redirect form in check-out pane not fully merged causes JavaScript not loading
eric.chenchao’s picture

Issue summary: View changes
chris matthews’s picture

Assigned: eric.chenchao » Unassigned

The 4 year old patch in #2 to commerce_payment.checkout_pane.inc applied cleanly to the latest commerce 7.x-1.x-dev, but still needs review.