Skip to content
Snippets Groups Projects
Commit f59a27c7 authored by Arjun Kumar's avatar Arjun Kumar
Browse files

Issue #3486543: Update cancel button functionality for add and update task.

parent 3b85ca2c
No related branches found
No related tags found
1 merge request!16Issue #3486543: Update cancel button functionality for add and update task.
......@@ -70,7 +70,7 @@ class AddTaskForm extends FormBase {
$form['actions']['reset'] = [
'#type' => 'submit',
'#value' => $this->t('Reset'),
'#value' => $this->t('Cancel'),
'#button_type' => 'secondry',
];
return $form;
......@@ -88,19 +88,26 @@ class AddTaskForm extends FormBase {
public function submitForm(array &$form, FormStateInterface $form_state) {
$current_path = \Drupal::service('path.current')->getPath();
$uri = 'tasks';
$message = $this->t('A new task has been created.');
$body = [
"content" => $form_state->getValue('task'),
"description" => $form_state->getValue('task_description'),
"due_string" => $form_state->getValue('task_due_data'),
];
try {
if($form_state->getValue('op') == 'Cancel'){
return $form_state->setRedirect('todoist_api.taskscontroller');
}
if (preg_match('/\bedit\b/', $current_path)) {
$body['type'] = 'edit';
$id = \Drupal::request()->get('id');
$message = $this->t('A task has been updated.');
}
$response = \Drupal::service('todoist_api.client')->post($uri, $body, $id);
if ($response) :
$this->messenger()->addStatus($this->t('A new task has been created.'));
$this->messenger()->addStatus($message);
$form_state->setRedirect('todoist_api.taskscontroller');
endif;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment