Commit e4ff866c authored by Gorodkov Denis's avatar Gorodkov Denis

commit

parent 5d4b6603
......@@ -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\CacheableMetadata;
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);
......
......@@ -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;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment