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));
Comments
Comment #1
eric.chenchao commentedComment #2
eric.chenchao commentedPatch attached.
Comment #3
eric.chenchao commentedComment #4
eric.chenchao commentedComment #5
chris matthews commentedThe 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.