Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
todoist_api
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
todoist_api
Commits
5280fc97
Commit
5280fc97
authored
9 months ago
by
Arjun Kumar
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3485276
: Add complete task functionality
parent
27ede30c
Branches
Branches containing commit
No related tags found
1 merge request
!4
Issue #3485276: Add complete task functionality
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Form/CloseTaskForm.php
+80
-0
80 additions, 0 deletions
src/Form/CloseTaskForm.php
todoist_api.routing.yml
+9
-0
9 additions, 0 deletions
todoist_api.routing.yml
with
89 additions
and
0 deletions
src/Form/CloseTaskForm.php
0 → 100644
+
80
−
0
View file @
5280fc97
<?php
namespace
Drupal\todoist_api\Form
;
use
Drupal\Core\Form\ConfirmFormBase
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Url
;
use
GuzzleHttp\Exception\RequestException
;
use
Drupal\Component\Serialization\Json
;
/**
* Defines a confirmation form to confirm deletion of something by id.
*/
class
CloseTaskForm
extends
ConfirmFormBase
{
/**
* ID of the item to delete.
*
* @var int
*/
protected
$id
;
/**
* ID of the item to delete.
*
* @var object
*/
protected
$todoistclient
;
/**
* {@inheritdoc}
*/
public
function
buildForm
(
array
$form
,
FormStateInterface
$form_state
,
string
$id
=
NULL
)
{
$this
->
id
=
$id
;
return
parent
::
buildForm
(
$form
,
$form_state
);
}
/**
* {@inheritdoc}
*/
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
// @todo: Do the deletion.
$uri
=
'tasks'
;
$content_id
=
$this
->
id
;
try
{
$response
=
\Drupal
::
service
(
'todoist_api.client'
)
->
post
(
$uri
,
null
,
$content_id
);
if
(
$response
)
:
$this
->
messenger
()
->
addStatus
(
$this
->
t
(
'One task has been completed.'
));
$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 try again later.'
));
}
}
/**
* {@inheritdoc}
*/
public
function
getFormId
()
:
string
{
return
"task_close_form"
;
}
/**
* {@inheritdoc}
*/
public
function
getCancelUrl
()
{
return
new
Url
(
'todoist_api.taskscontroller'
);
}
/**
* {@inheritdoc}
*/
public
function
getQuestion
()
{
$uri
=
'tasks'
;
$content_id
=
$this
->
id
;
return
$this
->
t
(
'Do you want to close the %id?'
,
[
'%id'
=>
$this
->
id
]);
}
}
This diff is collapsed.
Click to expand it.
todoist_api.routing.yml
+
9
−
0
View file @
5280fc97
...
...
@@ -26,3 +26,12 @@ todoist_api.deletetask:
requirements
:
_permission
:
'
user
todoist
access'
id
:
^\d+$
todoist_api.closetask
:
path
:
'
/admin/content/todoist/{id}/close'
defaults
:
_form
:
'
\Drupal\todoist_api\Form\CloseTaskForm'
_title
:
'
Complete
Task'
requirements
:
_permission
:
'
user
todoist
access'
id
:
^\d+$
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment