CampaignMonitorListDeleteForm.php in Campaign Monitor 8.2
File
src/Form/CampaignMonitorListDeleteForm.php
View source
<?php
namespace Drupal\campaignmonitor\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\campaignmonitor\CampaignMonitorManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
class CampaignMonitorListDeleteForm extends ConfirmFormBase {
protected $campaignMonitorManager;
protected $id;
public function __construct(CampaignMonitorManager $campaignmonitor_manager) {
$this->campaignMonitorManager = $campaignmonitor_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('campaignmonitor.manager'));
}
public function getFormId() {
return 'campaignmonitor_list_delete';
}
public function getQuestion() {
$options = $this->campaignMonitorManager
->getExtendedList($this->id);
return $this
->t('Do you want to delete %name?', [
'%name' => $options['name'],
]);
}
public function getCancelUrl() {
return new Url('campaignmonitor.lists');
}
public function getDescription() {
return $this
->t('Only do this if you are sure!');
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function getCancelText() {
return $this
->t('Cancel');
}
public function buildForm(array $form, FormStateInterface $form_state, $list_id = NULL) {
$this->id = $list_id;
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($this->campaignMonitorManager
->deleteList($this
->id())) {
$this
->messenger()
->addStatus($this
->t('The list has been deleted.'));
}
else {
$this
->messenger()
->addError($this
->t('The list could not be deleted.'));
}
$url = Url::fromRoute('campaignmonitor.refresh_lists');
$form_state
->setRedirectUrl($url);
}
}