OrderReceiptResendForm.php in Commerce Core 8.2
File
modules/order/src/Form/OrderReceiptResendForm.php
View source
<?php
namespace Drupal\commerce_order\Form;
use Drupal\commerce_order\Mail\OrderReceiptMailInterface;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Entity\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class OrderReceiptResendForm extends ContentEntityConfirmFormBase {
protected $orderReceiptMail;
public function __construct(EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info, TimeInterface $time, OrderReceiptMailInterface $order_receipt_mail) {
parent::__construct($entity_repository, $entity_type_bundle_info, $time);
$this->orderReceiptMail = $order_receipt_mail;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity.repository'), $container
->get('entity_type.bundle.info'), $container
->get('datetime.time'), $container
->get('commerce_order.order_receipt_mail'));
}
public function getQuestion() {
return $this
->t('Are you sure you want to resend the receipt for order %label?', [
'%label' => $this->entity
->label(),
]);
}
public function getConfirmText() {
return $this
->t('Resend receipt');
}
public function getCancelUrl() {
return $this->entity
->toUrl('collection');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$order = $this->entity;
$result = $this->orderReceiptMail
->send($order);
if ($result) {
$this
->messenger()
->addMessage($this
->t('Order receipt resent.'));
}
}
}