diff --git a/core/modules/dblog/src/Plugin/rest/resource/DBLogResource.php b/core/modules/dblog/src/Plugin/rest/resource/DBLogResource.php index 56740ca..26ec4f3 100644 --- a/core/modules/dblog/src/Plugin/rest/resource/DBLogResource.php +++ b/core/modules/dblog/src/Plugin/rest/resource/DBLogResource.php @@ -8,7 +8,7 @@ namespace Drupal\dblog\Plugin\rest\resource; use Drupal\rest\Plugin\ResourceBase; -use Drupal\rest\ResourceResponse; +use Drupal\rest\CacheableResourceResponse; use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -33,7 +33,7 @@ class DBLogResource extends ResourceBase { * @param int $id * The ID of the watchdog log entry. * - * @return \Drupal\rest\ResourceResponse + * @return \Drupal\rest\CacheableResourceResponse * The response containing the log entry. * * @throws \Symfony\Component\HttpKernel\Exception\HttpException @@ -43,7 +43,7 @@ public function get($id = NULL) { $record = db_query("SELECT * FROM {watchdog} WHERE wid = :wid", array(':wid' => $id)) ->fetchAssoc(); if (!empty($record)) { - return new ResourceResponse($record); + return new CacheableResourceResponse($record); } throw new NotFoundHttpException(t('Log entry with ID @id was not found', array('@id' => $id))); diff --git a/core/modules/rest/src/CacheableResourceResponse.php b/core/modules/rest/src/CacheableResourceResponse.php index 77ce629..ff4180c 100644 --- a/core/modules/rest/src/CacheableResourceResponse.php +++ b/core/modules/rest/src/CacheableResourceResponse.php @@ -17,4 +17,19 @@ class CacheableResourceResponse extends Response implements CacheableResponseInt use CacheableResponseTrait; use ResourceResponseTrait; + /** + * Constructor for CacheableResourceResponse objects. + * + * @param mixed $data + * Response data that should be serialized. + * @param int $status + * The response status code. + * @param array $headers + * An array of response headers. + */ + public function __construct($data = NULL, $status = 200, $headers = array()) { + $this->responseData = $data; + parent::__construct('', $status, $headers); + } + } diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php index 63d94cb..bf5c5f9 100644 --- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php +++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php @@ -111,7 +111,7 @@ public function post(EntityInterface $entity = NULL) { // 201 Created responses have an empty body. $url = $entity->urlInfo('canonical', ['absolute' => TRUE])->toString(TRUE); $response = new UncacheableResourceResponse(NULL, 201, ['Location' => $url->getGeneratedUrl()]); - $response->addCacheableDependency($url); + //$response->addCacheableDependency($url); return $response; } catch (EntityStorageException $e) { diff --git a/core/modules/rest/src/RequestHandler.php b/core/modules/rest/src/RequestHandler.php index 60f8695..4d683bf 100644 --- a/core/modules/rest/src/RequestHandler.php +++ b/core/modules/rest/src/RequestHandler.php @@ -107,7 +107,7 @@ public function handle(RouteMatchInterface $route_match, Request $request) { } // Serialize the outgoing data for the response, if available. - if ($response instanceof ResourceResponse && $data = $response->getResponseData()) { + if ($response instanceof CacheableResourceResponse && $data = $response->getResponseData()) { // Serialization can invoke rendering (e.g., generating URLs), but the // serialization API does not provide a mechanism to collect the // bubbleable metadata associated with that (e.g., language and other diff --git a/core/modules/rest/src/ResourceResponseTrait.php b/core/modules/rest/src/ResourceResponseTrait.php index 01e6c1b..74a19c8 100644 --- a/core/modules/rest/src/ResourceResponseTrait.php +++ b/core/modules/rest/src/ResourceResponseTrait.php @@ -7,14 +7,7 @@ namespace Drupal\rest; -/** - * Contains data for serialization before sending the response. - * - * We do not want to abuse the $content property on the Response class to store - * our response data. $content implies that the provided data must either be a - * string or an object with a __toString() method, which is not a requirement - * for data used here. - */ + Trait ResourceResponseTrait { /** @@ -25,21 +18,6 @@ protected $responseData; /** - * Constructor for ResourceResponse objects. - * - * @param mixed $data - * Response data that should be serialized. - * @param int $status - * The response status code. - * @param array $headers - * An array of response headers. - */ - public function __construct($data = NULL, $status = 200, $headers = array()) { - $this->responseData = $data; - parent::__construct('', $status, $headers); - } - - /** * Returns response data that should be serialized. * * @return mixed @@ -48,4 +26,4 @@ public function __construct($data = NULL, $status = 200, $headers = array()) { public function getResponseData() { return $this->responseData; } -} +} \ No newline at end of file diff --git a/core/modules/rest/src/UncacheableResourceResponse.php b/core/modules/rest/src/UncacheableResourceResponse.php index e3dd475..74e2cc1 100644 --- a/core/modules/rest/src/UncacheableResourceResponse.php +++ b/core/modules/rest/src/UncacheableResourceResponse.php @@ -9,9 +9,22 @@ use Symfony\Component\HttpFoundation\Response; - class UncacheableResourceResponse extends Response { use ResourceResponseTrait; + /** + * Constructor for UncacheableResourceResponse objects. + * + * @param mixed $data + * Response data that should be serialized. + * @param int $status + * The response status code. + * @param array $headers + * An array of response headers. + */ + public function __construct($data = NULL, $status = 200, $headers = array()) { + $this->responseData = $data; + parent::__construct('', $status, $headers); + } } \ No newline at end of file