Delete.php in SimpleAds 8
File
src/Form/Ads/Delete.php
View source
<?php
namespace Drupal\simpleads\Form\Ads;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\simpleads\Ads;
class Delete extends ConfirmFormBase {
protected $ad;
public function getFormId() {
return 'simpleads_delete_form';
}
public function getQuestion() {
return t('Are you sure you would like to delete <em>%name</em>?', [
'%name' => $this->ad
->getAdName(),
]);
}
public function getCancelUrl() {
return new Url('simpleads.ads');
}
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 Advertisement');
}
public function getCancelText() {
return $this
->t('Cancel');
}
public function buildForm(array $form, FormStateInterface $form_state, $type = NULL, $id = NULL) {
$form['ad_type'] = [
'#type' => 'hidden',
'#value' => $type,
];
$form['id'] = [
'#type' => 'hidden',
'#value' => $id,
];
$this->ad = (new Ads())
->setId($id)
->load();
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$options = $this->ad
->getOptions(TRUE);
$this->ad
->getSubmitForm('delete', $options, $form_state, $form_state
->getValue('ad_type'), $form_state
->getValue('id'));
$this->ad
->delete();
$form_state
->setRedirect('simpleads.ads');
}
}
Classes
Name |
Description |
Delete |
Delete advertisement form. |