MailchimpCampaignSendForm.php in Mailchimp 8
File
modules/mailchimp_campaign/src/Form/MailchimpCampaignSendForm.php
View source
<?php
namespace Drupal\mailchimp_campaign\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Url;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class MailchimpCampaignSendForm extends EntityConfirmFormBase {
protected $messenger;
public function __construct(MessengerInterface $messenger) {
$this->messenger = $messenger;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('messenger'));
}
public function getQuestion() {
return $this
->t('Are you sure you want to send %name?', [
'%name' => $this->entity
->label(),
]);
}
public function getDescription() {
return $this
->t('This action will send the campaign through Mailchimp and cannot be undone.');
}
public function getCancelUrl() {
return new Url('mailchimp_campaign.overview');
}
public function getConfirmText() {
return $this
->t('Send campaign');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
if (mailchimp_campaign_send_campaign($this->entity)) {
$this->messenger
->addStatus($this
->t('Mailchimp Campaign %name has been sent.', [
'%name' => $this->entity
->label(),
]));
}
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
public function afterBuild(array $element, FormStateInterface $form_state) {
return $element;
}
}