class NodeDateArgumentDefaultPluginBase
Provides a base class for node date values.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\DependencyInjection\AutowiredInstanceTrait, \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
- class \Drupal\views\Plugin\views\PluginBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase extends \Drupal\views\Plugin\views\PluginBase
- class \Drupal\node\Plugin\views\argument_default\NodeDateArgumentDefaultPluginBase implements \Drupal\Core\Cache\CacheableDependencyInterface extends \Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase
- class \Drupal\views\Plugin\views\argument_default\ArgumentDefaultPluginBase extends \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\PluginBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\DependencyInjection\AutowiredInstanceTrait, \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of NodeDateArgumentDefaultPluginBase
File
-
core/
modules/ node/ src/ Plugin/ views/ argument_default/ NodeDateArgumentDefaultPluginBase.php, line 17
Namespace
Drupal\node\Plugin\views\argument_defaultView source
abstract class NodeDateArgumentDefaultPluginBase extends ArgumentDefaultPluginBase implements CacheableDependencyInterface {
/**
* Constructs a new NodeDateArgumentDefaultPluginBase instance.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch
* The route match.
* @param \Drupal\Core\Datetime\DateFormatterInterface $dateFormatter
* The date formatter service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, protected RouteMatchInterface $routeMatch, protected DateFormatterInterface $dateFormatter) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) : static {
return new static($configuration, $plugin_id, $plugin_definition, $container->get('current_route_match'), $container->get('date.formatter'));
}
/**
* {@inheritdoc}
*/
public function getArgument() : string|bool {
// Return a time value from the current node if available.
if (($node = $this->routeMatch
->getParameter('node')) && $node instanceof NodeInterface) {
// The Date argument handlers provide their own format strings, otherwise
// use a default.
$format = $this->argument instanceof Date ? $this->argument
->getArgFormat() : 'Y-m-d';
return $this->dateFormatter
->format($this->getNodeDateValue($node), 'custom', $format);
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
return [
'url',
];
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
return Cache::PERMANENT;
}
/**
* Gets a timestamp value from the passed node.
*
* @param \Drupal\node\NodeInterface $node
* The node to get the timestamp value from.
*
* @return int
* A timestamp value from a node field.
*/
abstract protected function getNodeDateValue(NodeInterface $node) : int;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.