Skip to content
Snippets Groups Projects
Unverified Commit 960fb521 authored by Rolando Payán Mosqueda's avatar Rolando Payán Mosqueda Committed by Pedro Cambra
Browse files

Issue #3336092: Use the configurable cookie lifetime for the like controller as well

parent 8d1b4535
No related branches found
No related tags found
1 merge request!6Resolve #3361494 "Add readme file"
......@@ -2,6 +2,7 @@
namespace Drupal\like\Controller;
use DateTime;
use Drupal\Core\Cache\CacheableJsonResponse;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Controller\ControllerBase;
......@@ -32,10 +33,14 @@ class LikeController extends ControllerBase {
'likes' => $entity->get('likes')->value ?? 0,
]);
$like_cookie_expiry_time = $this->config('like.settings')->get('like_cookie_expiry_time');
$cacheMetadata = new CacheableMetadata();
$cacheMetadata->setCacheMaxAge(300);
$cacheMetadata->setCacheMaxAge($like_cookie_expiry_time);
$response->addCacheableDependency($cacheMetadata);
$response->setExpires(new \DateTime('300 sec'));
$response->setExpires(new DateTime('+' . $like_cookie_expiry_time . ' seconds'));
$settings = $this->config('like.settings');
$response->addCacheableDependency($settings);
return $response;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment