DeleteForm.php in Optimizely 8.3
File
src/Form/DeleteForm.php
View source
<?php
namespace Drupal\optimizely\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\optimizely\Util\CacheRefresher;
class DeleteForm extends ConfirmFormBase {
private $oid = NULL;
public function getFormId() {
return 'optimizely-delete-page-confirm';
}
public function getQuestion() {
return $this
->t('Delete');
}
public function getDescription() {
return $this
->t('Are you sure you want to delete this configuration?
<p>This action cannot be undone.</p>');
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function getCancelUrl() {
return new Url('optimizely.listing');
}
public function buildForm(array $form, FormStateInterface $form_state, $oid = NULL) {
$this->oid = $oid;
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($this->oid == 1) {
drupal_set_message($this
->t('Default project cannot be deleted.'), 'error');
$form_state
->setRedirect('optimizely.listing');
return;
}
$query = \Drupal::database()
->select('optimizely', 'o', [
'target' => 'slave',
])
->fields('o', [
'path',
'enabled',
])
->condition('o.oid', $this->oid, '=');
$record = $query
->execute()
->fetchObject();
$query = \Drupal::database()
->delete('optimizely')
->condition('oid', $this->oid);
$query
->execute();
if ($record->enabled) {
$path_array = unserialize($record->path);
CacheRefresher::doRefresh($path_array);
}
drupal_set_message(t('The project entry has been deleted.'), 'status');
$form_state
->setRedirect('optimizely.listing');
}
}
Classes
Name |
Description |
DeleteForm |
Implements the confirmation form for deleting a project. |