By jsacksick on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
3.0.x
Introduced in version:
3.0.0
Issue links:
Description:
Since #3462426: Drupal 11 compatibility fixes for commerce, payment gateway plugins requiring additional dependencies are now required to override the create() rather than the constructor.
The parent create() method must be called so logic from the PaymentGatewayBase is properly invoked.
This change was implemented so that payment gateway plugins no longer have to keep up with the dependencies required by the PaymentGatewayBase
Example with the Manual payment gateway plugin defined by Commerce core:
Before:
/**
* Constructs a new Manual object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\commerce_payment\PaymentTypeManager $payment_type_manager
* The payment type manager.
* @param \Drupal\commerce_payment\PaymentMethodTypeManager $payment_method_type_manager
* The payment method type manager.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time.
* @param \Drupal\commerce_price\MinorUnitsConverterInterface $minor_units_converter
* The minor units converter.
* @param \Drupal\Core\Utility\Token $token
* The token service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager, PaymentTypeManager $payment_type_manager, PaymentMethodTypeManager $payment_method_type_manager, TimeInterface $time, MinorUnitsConverterInterface $minor_units_converter, Token $token) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type_manager, $payment_type_manager, $payment_method_type_manager, $time, $minor_units_converter);
$this->token = $token;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('entity_type.manager'),
$container->get('plugin.manager.commerce_payment_type'),
$container->get('plugin.manager.commerce_payment_method_type'),
$container->get('datetime.time'),
$container->get('commerce_price.minor_units_converter'),
$container->get('token')
);
After:
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
$instance = parent::create($container, $configuration, $plugin_id, $plugin_definition);
$instance->token = $container->get('token');
return $instance;
}
Impacts:
Module developers