Date.php in Calendar 8
File
calendar_datetime/src/Plugin/views/argument_default/Date.php
View source
<?php
namespace Drupal\calendar_datetime\Plugin\views\argument_default;
use Drupal\Core\Cache\CacheableDependencyInterface;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
class Date extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {
protected $dateFormatter;
protected $request;
public function __construct(array $configuration, $plugin_id, $plugin_definition, DateFormatterInterface $date_formatter, Request $request) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->dateFormatter = $date_formatter;
$this->request = $request;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('date.formatter'), $container
->get('request_stack')
->getCurrentRequest());
}
public function getArgument() {
$argument = $this->argument;
if ($argument instanceof Date) {
$format = $argument
->getArgFormat();
}
else {
$format = 'Y-m-d';
}
$request_time = $this->request->server
->get('REQUEST_TIME');
return $this->dateFormatter
->format($request_time, 'custom', $format);
}
public function getCacheContexts() {
return [];
}
public function getCacheMaxAge() {
return 0;
}
}
Classes
Name |
Description |
Date |
The current date argument default handler. |