Skip to content
Snippets Groups Projects

[#3290418] Drupal 10 compatibility

5 files
+ 18
9
Compare changes
  • Side-by-side
  • Inline
Files
5
@@ -2,6 +2,7 @@
namespace Drupal\views_advanced_cache\Plugin\views\cache;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Datetime\DateFormatterInterface;
@@ -42,6 +43,13 @@ class AdvancedViewsCache extends CachePluginBase {
*/
protected $dateFormatter;
/**
* The time service.
*
* @var \Drupal\Component\Datetime\TimeInterface
*/
protected $time;
protected $lifespans = [60, 300, 900, 1800, 3600, 21600, 43200, 86400, 604800];
public $lifespanOptions = [];
@@ -49,8 +57,9 @@ class AdvancedViewsCache extends CachePluginBase {
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, DateFormatterInterface $date_formatter) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, DateFormatterInterface $date_formatter, TimeInterface $datetime_time) {
$this->dateFormatter = $date_formatter;
$this->time = $datetime_time;
parent::__construct($configuration, $plugin_id, $plugin_definition);
@@ -66,7 +75,8 @@ class AdvancedViewsCache extends CachePluginBase {
$configuration,
$plugin_id,
$plugin_definition,
$container->get('date.formatter')
$container->get('date.formatter'),
$container->get('datetime.time')
);
}
@@ -414,7 +424,7 @@ class AdvancedViewsCache extends CachePluginBase {
protected function cacheExpire($type) {
$lifespan = $this->getLifespan($type);
if ($lifespan >= 0) {
$cutoff = REQUEST_TIME - $lifespan;
$cutoff = $this->time->getRequestTime() - $lifespan;
return $cutoff;
}
else {
Loading