ShipmentConfirmationResendForm.php in Commerce Shipping 8.2
File
src/Form/ShipmentConfirmationResendForm.php
View source
<?php
namespace Drupal\commerce_shipping\Form;
use Drupal\commerce_shipping\Mail\ShipmentConfirmationMailInterface;
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 ShipmentConfirmationResendForm extends ContentEntityConfirmFormBase {
protected $shipmentConfirmationMail;
public function __construct(EntityRepositoryInterface $entity_repository, EntityTypeBundleInfoInterface $entity_type_bundle_info, TimeInterface $time, ShipmentConfirmationMailInterface $shipment_confirmation_mail) {
parent::__construct($entity_repository, $entity_type_bundle_info, $time);
$this->shipmentConfirmationMail = $shipment_confirmation_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_shipping.shipment_confirmation_mail'));
}
public function getQuestion() {
return $this
->t('Are you sure you want to resend the shipment confirmation for %shipment for order %order?', [
'%shipment' => $this->entity
->label(),
'%order' => $this->entity
->getOrder()
->label(),
]);
}
public function getConfirmText() {
return $this
->t('Resend confirmation');
}
public function getCancelUrl() {
return $this->entity
->toUrl('collection');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$shipment = $this->entity;
$result = $this->shipmentConfirmationMail
->send($shipment);
if ($result) {
$this
->messenger()
->addMessage($this
->t('Shipment confirmation resent.'));
}
}
}