public function DeleteForm::submitForm in Optimizely 8
Same name and namespace in other branches
- 8.0 src/DeleteForm.php \Drupal\optimizely\DeleteForm::submitForm()
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- src/
DeleteForm.php, line 67
Class
- DeleteForm
- Implements the confirmation form for deleting a project.
Namespace
Drupal\optimizelyCode
public function submitForm(array &$form, FormStateInterface $form_state) {
// Prevent deletion of default project.
if ($this->oid == 1) {
drupal_set_message($this
->t('Default project cannot be deleted.'), 'error');
// Return to project listing page.
$form_state
->setRedirect('optimizely.listing');
return;
}
// Lookup entry details before delete.
$query = \Drupal::database()
->select('optimizely', 'o', [
'target' => 'slave',
])
->fields('o', [
'path',
'enabled',
])
->condition('o.oid', $this->oid, '=');
$record = $query
->execute()
->fetchObject();
// Delete entry in database based on the target $oid.
$query = \Drupal::database()
->delete('optimizely')
->condition('oid', $this->oid);
$query
->execute();
// Only clear page cache for entries that are active when deleted.
if ($record->enabled) {
// Always serialized when saved.
$path_array = unserialize($record->path);
CacheRefresher::doRefresh($path_array);
}
drupal_set_message(t('The project entry has been deleted.'), 'status');
// Return to project listing page.
$form_state
->setRedirect('optimizely.listing');
}