function commerce_square_form_alter in Commerce Square Connect 7
Implements hook_form_alter().
Workaround https://www.drupal.org/node/1988968#comment-12032406. We need to add the js files to the payment method selection since drupal AJAX cannot ensure the proper loading of new js files.
File
- ./
commerce_square.module, line 715 - Module file for Commerce Square.
Code
function commerce_square_form_alter(&$form, $form_state) {
$square_payment_method = FALSE;
if (isset($form['commerce_payment']['payment_methods']['#value']) && is_array($form['commerce_payment']['payment_methods']['#value'])) {
foreach ($form['commerce_payment']['payment_methods']['#value'] as $key => $method) {
if ($method['method_id'] === 'commerce_square') {
$square_payment_method = TRUE;
break;
}
}
if ($square_payment_method) {
_commerce_square_ensure_assets_attached($form, $method['settings']['mode']);
}
}
}