You are here

function commerce_paypal_js_alter in Commerce PayPal 8

Implements hook_js_alter().

File

./commerce_paypal.module, line 205
Implements PayPal payment services for use with Drupal Commerce.

Code

function commerce_paypal_js_alter(&$javascript, \Drupal\Core\Asset\AttachedAssetsInterface $assets) {
  $client_id = \Drupal::config('commerce_paypal.credit_messaging_settings')
    ->get('client_id');
  if (!$client_id) {
    return;
  }
  $paypal_checkout_js = drupal_get_path('module', 'commerce_paypal') . '/js/paypal-checkout.js';

  // The paypal-checkout JS file isn't present, no need to do anything.
  if (!isset($javascript[$paypal_checkout_js])) {
    return;
  }

  // Remove the extra JS SDK added for credit messaging library if present.
  foreach ($javascript as $key => $js) {
    if (strpos($key, 'https://www.paypal.com/sdk/js') === 0) {
      unset($javascript[$key]);
      break;
    }
  }
}