PaymentMethodEditForm.php in Commerce Core 8.2
File
modules/payment/src/Form/PaymentMethodEditForm.php
View source
<?php
namespace Drupal\commerce_payment\Form;
use Drupal\commerce\InlineFormManager;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class PaymentMethodEditForm extends EntityForm implements ContainerInjectionInterface {
protected $inlineFormManager;
public function __construct(InlineFormManager $inline_form_manager) {
$this->inlineFormManager = $inline_form_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('plugin.manager.commerce_inline_form'));
}
public function buildForm(array $form, FormStateInterface $form_state) {
$inline_form = $this->inlineFormManager
->createInstance('payment_gateway_form', [
'operation' => 'edit-payment-method',
], $this->entity);
$form['payment_method'] = [
'#parents' => [
'payment_method',
],
'#inline_form' => $inline_form,
];
$form['payment_method'] = $inline_form
->buildInlineForm($form['payment_method'], $form_state);
$form['actions'] = $this
->actionsElement($form, $form_state);
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$inline_form = $form['payment_method']['#inline_form'];
$payment_method = $inline_form
->getEntity();
$this
->messenger()
->addMessage($this
->t('Saved the %label payment method.', [
'%label' => $this->entity
->label(),
]));
$form_state
->setRedirectUrl($payment_method
->toUrl('collection'));
}
public function save(array $form, FormStateInterface $form_state) {
}
}