Delete.php in SimpleAds 8
File
src/Form/Campaigns/Delete.php
View source
<?php
namespace Drupal\simpleads\Form\Campaigns;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\simpleads\Campaigns;
class Delete extends ConfirmFormBase {
protected $campaign;
public function getFormId() {
return 'simpleads_delete_form';
}
public function getQuestion() {
return t('Are you sure you would like to delete <em>%name</em> campaign?', [
'%name' => $this->campaign
->getCampaignName(),
]);
}
public function getCancelUrl() {
return new Url('simpleads.campaigns');
}
public function getDescription() {
return t('Are you sure you would like to continue? This operation cannot be undone.');
}
public function getConfirmText() {
return $this
->t('Delete Campaign');
}
public function getCancelText() {
return $this
->t('Cancel');
}
public function buildForm(array $form, FormStateInterface $form_state, $type = NULL, $id = NULL) {
$form['campaign_type'] = [
'#type' => 'hidden',
'#value' => $type,
];
$form['id'] = [
'#type' => 'hidden',
'#value' => $id,
];
$this->campaign = (new Campaigns())
->setId($id)
->load();
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$options = $this->campaign
->getOptions(TRUE);
$this->campaign
->getSubmitForm('delete', $options, $form_state, $form_state
->getValue('campaign_type'), $form_state
->getValue('id'));
$this->campaign
->delete();
$form_state
->setRedirect('simpleads.campaigns');
}
}
Classes
Name |
Description |
Delete |
Delete advertisement campaign form. |