Skip to content
Snippets Groups Projects

Resolve #3485274 "Task delete functionality"

1 file
+ 12
4
Compare changes
  • Side-by-side
  • Inline
@@ -5,6 +5,7 @@ namespace Drupal\todoist_api\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use GuzzleHttp\Exception\RequestException;
/**
* Defines a confirmation form to confirm deletion of something by id.
@@ -40,11 +41,18 @@ class DeleteTaskForm extends ConfirmFormBase {
// @todo: Do the deletion.
$uri = 'tasks';
$content_id = $this->id;
$response = \Drupal::service('todoist_api.client')->delete($uri, $content_id);
if($response):
$this->messenger()->addStatus($this->t('A task has been deleted.'));
try{
$response = \Drupal::service('todoist_api.client')->delete($uri, $content_id);
if($response):
$this->messenger()->addStatus($this->t('A task has been deleted.'));
$form_state->setRedirect('todoist_api.taskscontroller');
endif;
} catch( RequestException $exception) {
\Drupal::logger('error_rest_client')->notice($exception->getMessage());
$form_state->setErrorByName('task', $this->t('Application error. Please check your logs.'));
$form_state->setRedirect('todoist_api.taskscontroller');
endif;
}
}
/**
Loading