Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
Project
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Jobs
Commits
Open sidebar
Gorodkov Denis
Project
Commits
e4ff866c
Commit
e4ff866c
authored
May 19, 2022
by
Gorodkov Denis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit
parent
5d4b6603
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
40 deletions
+6
-40
GetPeoples.php
...s/custom/mymodule/src/Plugin/rest/resource/GetPeoples.php
+6
-8
PostPeople.php
...s/custom/mymodule/src/Plugin/rest/resource/PostPeople.php
+0
-32
No files found.
app/docroot/modules/custom/mymodule/src/Plugin/rest/resource/GetPeoples.php
View file @
e4ff866c
...
...
@@ -2,12 +2,13 @@
namespace
Drupal\mymodule\Plugin\rest\resource
;
use
Drupal\Core\Cache\CacheableMetadata
;
use
Drupal\rest\Plugin\ResourceBase
;
use
Drupal\rest\ResourceResponse
;
use
Symfony\Component\HttpFoundation\JsonResponse
;
use
Symfony\Component\HttpFoundation\Response
;
use
\Drupal\node\Entity\Node
;
use
\Drupal\Core\Cache\Cache
ableMetadata
;
use
\Drupal\Core\Cache\Cache
;
/**
...
...
@@ -27,16 +28,13 @@ class GetPeoples extends ResourceBase {
public
function
get
()
{
$query
=
\Drupal
::
request
()
->
query
->
get
(
'page'
);
$cache
=
new
CacheableMetadata
();
$cache
->
setCacheMaxAge
(
900
);
if
(
empty
(
$query
))
{
$query
=
1
;
}
$cache
=
CacheableMetadata
::
createFromRenderArray
([
'#cache'
=>
[
'max-age'
=>
900
,
],
]);
$nodes
=
\Drupal
::
entityTypeManager
()
->
getStorage
(
'node'
)
->
loadByProperties
([
...
...
@@ -111,7 +109,7 @@ class GetPeoples extends ResourceBase {
$result
[
'url'
]
=
$url
->
getGeneratedUrl
();
$response
[
'results'
][]
=
$result
;
#
$cache->addCacheableDependency($node);
$cache
->
addCacheableDependency
(
$node
);
}
}
$resource
=
new
ResourceResponse
(
$response
,
200
);
...
...
app/docroot/modules/custom/mymodule/src/Plugin/rest/resource/PostPeople.php
View file @
e4ff866c
...
...
@@ -18,37 +18,5 @@ use Drupal\Core\Cache\CacheableMetadata;
* )
*/
class
PostPeople
extends
ResourceBase
{
/**
* {@inheritdoc}
*/
public
function
get
()
{
$cache
=
CacheableMetadata
::
createFromRenderArray
([
'#cache'
=>
[
'max-age'
=>
600
,
],
]);
$nodes
=
\Drupal
::
entityTypeManager
()
->
getStorage
(
'node'
)
->
loadByProperties
([
'type'
=>
'people'
,
'field_swapi_id'
=>
1
,
]);
foreach
(
$nodes
as
$item
)
{
$node
=
$item
;
}
$response
=
new
ResourceResponse
(
[
'title'
=>
$node
->
label
(),
'time'
=>
time
(),
]
);
#$cache->addCacheableDependency($node);
$response
->
addCacheableDependency
(
$cache
);
return
$response
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment