Skip to content

Instantly share code, notes, and snippets.

@clrockwell
Created October 1, 2017 14:57
Show Gist options
  • Save clrockwell/b055f9d0a4ec4509467b83ab4ff12e06 to your computer and use it in GitHub Desktop.
Save clrockwell/b055f9d0a4ec4509467b83ab4ff12e06 to your computer and use it in GitHub Desktop.
Example of creating a plugin instance with the default configuration
<?php
// using PayPal EC as example
/** @var PaymentGatewayManager $plugin */
$plugin = \Drupal::service('plugin.manager.commerce_payment_gateway');
// Get the id of config from `drupal debug:config | grep paypal`
/** @var Config $config */
$config = \Drupal::service('config.factory')
->get('commerce_payment.commerce_payment_gateway.paypal_ec');
/** @var ExpressCheckout $ppec */
$instance = $plugin->createInstance('paypal_express_checkout', $config->get());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment