ChecklistapiChecklistClearForm.php in Checklist API 8
File
src/Form/ChecklistapiChecklistClearForm.php
View source
<?php
namespace Drupal\checklistapi\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
class ChecklistapiChecklistClearForm extends ConfirmFormBase {
public $checklist;
public function getFormId() {
return 'checklistapi_checklist_clear_confirm';
}
public function getQuestion() {
return t('Are you sure you want to clear saved progress?');
}
public function getCancelUrl() {
return $this->checklist
->getUrl();
}
public function getDescription() {
return t('All progress details for %checklist will be erased. This action cannot be undone.', [
'%checklist' => $this->checklist->title,
]);
}
public function getConfirmText() {
return t('Clear');
}
public function getCancelText() {
return t('Cancel');
}
public function buildForm(array $form, FormStateInterface $form_state, $checklist_id = NULL) {
$this->checklist = checklistapi_checklist_load($checklist_id);
$form['#checklist'] = $this->checklist;
return parent::buildForm($form, $form_state);
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$form['#checklist']
->clearSavedProgress();
$form_state
->setRedirect($form['#checklist']
->getRouteName());
}
}