class PaymentMethodAddForm in Commerce PayPal 8
Hierarchy
- class \Drupal\Core\Plugin\PluginFormBase implements PluginAwareInterface, PluginFormInterface
- class \Drupal\commerce_payment\PluginForm\PaymentGatewayFormBase implements PaymentGatewayFormInterface uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\commerce_payment\PluginForm\PaymentMethodFormBase implements ContainerInjectionInterface
- class \Drupal\commerce_payment\PluginForm\PaymentMethodAddForm
- class \Drupal\commerce_paypal\PluginForm\Checkout\PaymentMethodAddForm
- class \Drupal\commerce_payment\PluginForm\PaymentMethodAddForm
- class \Drupal\commerce_payment\PluginForm\PaymentMethodFormBase implements ContainerInjectionInterface
- class \Drupal\commerce_payment\PluginForm\PaymentGatewayFormBase implements PaymentGatewayFormInterface uses DependencySerializationTrait, StringTranslationTrait
Expanded class hierarchy of PaymentMethodAddForm
File
- src/
PluginForm/ Checkout/ PaymentMethodAddForm.php, line 17
Namespace
Drupal\commerce_paypal\PluginForm\CheckoutView source
class PaymentMethodAddForm extends BasePaymentMethodAddForm {
/**
* The custom card fields builder.
*
* @var \Drupal\commerce_paypal\CustomCardFieldsBuilderInterface
*/
protected $cardFieldsBuilder;
/**
* The route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* Constructs a new PaymentMethodAddForm object.
*
* @param \Drupal\commerce_store\CurrentStoreInterface $current_store
* The current store.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\commerce\InlineFormManager $inline_form_manager
* The inline form manager.
* @param \Psr\Log\LoggerInterface $logger
* The logger.
* @param \Drupal\commerce_paypal\CustomCardFieldsBuilderInterface $card_fields_builder
* The custom card fields builder.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
*/
public function __construct(CurrentStoreInterface $current_store, EntityTypeManagerInterface $entity_type_manager, InlineFormManager $inline_form_manager, LoggerInterface $logger, CustomCardFieldsBuilderInterface $card_fields_builder, RouteMatchInterface $route_match) {
parent::__construct($current_store, $entity_type_manager, $inline_form_manager, $logger);
$this->cardFieldsBuilder = $card_fields_builder;
$this->routeMatch = $route_match;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('commerce_store.current_store'), $container
->get('entity_type.manager'), $container
->get('plugin.manager.commerce_inline_form'), $container
->get('logger.channel.commerce_payment'), $container
->get('commerce_paypal.custom_card_fields_builder'), $container
->get('current_route_match'));
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
/** @var \Drupal\commerce_payment\Entity\PaymentMethodInterface $payment_method */
$payment_method = $this->entity;
// We need to inject the custom card fields, only when this is the solution
// configured.
if (!$this
->shouldInjectForm($payment_method
->getPaymentGateway()
->getPlugin())) {
return $form;
}
/** @var \Drupal\commerce_order\Entity\OrderInterface $order */
$order = $this->routeMatch
->getParameter('commerce_order');
$form['payment_details'] += $this->cardFieldsBuilder
->build($order, $payment_method
->getPaymentGateway());
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\commerce_payment\Entity\PaymentMethodInterface $payment_method */
$payment_method = $this->entity;
$payment_method
->setReusable(FALSE);
// When the gateway is configured to display "Smart payment buttons", the
// buttons are not injected in the payment information pane but in the
// "review" step, which means the payment method creation should be skipped.
if ($this
->shouldInjectForm($payment_method
->getPaymentGateway()
->getPlugin())) {
parent::submitConfigurationForm($form, $form_state);
}
else {
// Since we're not calling the parent submitConfigurationForm() method
// we need to duplicate the logic for setting the billing profile
/** @var \Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OnsitePaymentGatewayInterface $payment_gateway_plugin */
$payment_gateway_plugin = $this->plugin;
/** @var \Drupal\commerce_payment\Entity\PaymentMethodInterface $payment_method */
$payment_method = $this->entity;
if ($payment_gateway_plugin
->collectsBillingInformation()) {
/** @var \Drupal\commerce\Plugin\Commerce\InlineForm\EntityInlineFormInterface $inline_form */
$inline_form = $form['billing_information']['#inline_form'];
/** @var \Drupal\profile\Entity\ProfileInterface $billing_profile */
$billing_profile = $inline_form
->getEntity();
$payment_method
->setBillingProfile($billing_profile);
}
}
}
/**
* Determines whether the card fields form should be injected.
*/
protected function shouldInjectForm(PaymentGatewayInterface $plugin) {
return $plugin instanceof CheckoutInterface && $plugin
->getPaymentSolution() === 'custom_card_fields';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
PaymentGatewayFormBase:: |
protected | property | The form entity. | |
PaymentGatewayFormBase:: |
public | function |
Gets the form entity. Overrides PaymentGatewayFormInterface:: |
|
PaymentGatewayFormBase:: |
public | function |
Sets the form entity. Overrides PaymentGatewayFormInterface:: |
|
PaymentMethodAddForm:: |
protected | property | The custom card fields builder. | |
PaymentMethodAddForm:: |
protected | property | The route match. | |
PaymentMethodAddForm:: |
public | function |
Form constructor. Overrides PaymentMethodAddForm:: |
|
PaymentMethodAddForm:: |
protected | function | Builds the credit card form. | 1 |
PaymentMethodAddForm:: |
protected | function | Builds the PayPal form. | |
PaymentMethodAddForm:: |
public static | function |
Instantiates a new instance of this class. Overrides PaymentMethodFormBase:: |
|
PaymentMethodAddForm:: |
public | function |
Gets the form element to which errors should be assigned. Overrides PaymentGatewayFormBase:: |
|
PaymentMethodAddForm:: |
protected | function | Determines whether the card fields form should be injected. | |
PaymentMethodAddForm:: |
public | function |
Form submission handler. Overrides PaymentMethodAddForm:: |
|
PaymentMethodAddForm:: |
protected | function | Handles the submission of the credit card form. | |
PaymentMethodAddForm:: |
protected | function | Handles the submission of the PayPal form. | |
PaymentMethodAddForm:: |
public | function |
Form validation handler. Overrides PaymentMethodFormBase:: |
|
PaymentMethodAddForm:: |
protected | function | Validates the credit card form. | |
PaymentMethodAddForm:: |
protected | function | Validates the PayPal form. | |
PaymentMethodAddForm:: |
public | function |
Constructs a new PaymentMethodAddForm object. Overrides PaymentMethodFormBase:: |
|
PaymentMethodFormBase:: |
protected | property | The current store. | |
PaymentMethodFormBase:: |
protected | property | The entity type manager. | |
PaymentMethodFormBase:: |
protected | property | The inline form manager. | |
PaymentMethodFormBase:: |
protected | property | The logger. | |
PluginFormBase:: |
protected | property | The plugin this form is for. | 3 |
PluginFormBase:: |
public | function |
Sets the plugin for this object. Overrides PluginAwareInterface:: |
1 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |