Date.php
Same filename in this branch
- 8.9.x core/modules/views/src/Plugin/views/sort/Date.php
- 8.9.x core/modules/views/src/Plugin/views/field/Date.php
- 8.9.x core/modules/views/src/Plugin/views/filter/Date.php
- 8.9.x core/modules/views/src/Plugin/views/argument/Date.php
- 8.9.x core/modules/datetime/src/Plugin/views/filter/Date.php
- 8.9.x core/modules/datetime/src/Plugin/views/argument/Date.php
- 8.9.x core/lib/Drupal/Core/Render/Element/Date.php
Same filename in other branches
- 9 core/modules/views/src/Plugin/views/sort/Date.php
- 9 core/modules/views/src/Plugin/views/field/Date.php
- 9 core/modules/views/src/Plugin/views/filter/Date.php
- 9 core/modules/views/src/Plugin/views/argument/Date.php
- 9 core/modules/datetime/src/Plugin/views/sort/Date.php
- 9 core/modules/datetime/src/Plugin/views/filter/Date.php
- 9 core/modules/datetime/src/Plugin/views/argument/Date.php
- 9 core/lib/Drupal/Core/Render/Element/Date.php
- 10 core/modules/views/src/Plugin/views/sort/Date.php
- 10 core/modules/views/src/Plugin/views/field/Date.php
- 10 core/modules/views/src/Plugin/views/filter/Date.php
- 10 core/modules/views/src/Plugin/views/argument/Date.php
- 10 core/modules/datetime/src/Plugin/views/sort/Date.php
- 10 core/modules/datetime/src/Plugin/views/filter/Date.php
- 10 core/modules/datetime/src/Plugin/views/argument/Date.php
- 10 core/lib/Drupal/Core/Render/Element/Date.php
- 11.x core/modules/views/src/Plugin/views/sort/Date.php
- 11.x core/modules/views/src/Plugin/views/field/Date.php
- 11.x core/modules/views/src/Plugin/views/filter/Date.php
- 11.x core/modules/views/src/Plugin/views/argument/Date.php
- 11.x core/modules/datetime/src/Plugin/views/sort/Date.php
- 11.x core/modules/datetime/src/Plugin/views/filter/Date.php
- 11.x core/modules/datetime/src/Plugin/views/argument/Date.php
- 11.x core/lib/Drupal/Core/Render/Element/Date.php
Namespace
Drupal\datetime\Plugin\views\sortFile
-
core/
modules/ datetime/ src/ Plugin/ views/ sort/ Date.php
View source
<?php
namespace Drupal\datetime\Plugin\views\sort;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItem;
use Drupal\views\FieldAPIHandlerTrait;
use Drupal\views\Plugin\views\sort\Date as NumericDate;
/**
* Basic sort handler for datetime fields.
*
* This handler enables granularity, which is the ability to make dates
* equivalent based upon nearness.
*
* @ViewsSort("datetime")
*/
class Date extends NumericDate {
use FieldAPIHandlerTrait;
/**
* Determines if the timezone offset is calculated.
*
* @var bool
*/
protected $calculateOffset = TRUE;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$definition = $this->getFieldStorageDefinition();
if ($definition->getSetting('datetime_type') === DateTimeItem::DATETIME_TYPE_DATE) {
// Timezone offset calculation is not applicable to dates that are stored
// as date-only.
$this->calculateOffset = FALSE;
}
}
/**
* {@inheritdoc}
*
* Override to account for dates stored as strings.
*/
public function getDateField() {
// Use string date storage/formatting since datetime fields are stored as
// strings rather than UNIX timestamps.
return $this->query
->getDateField("{$this->tableAlias}.{$this->realField}", TRUE, $this->calculateOffset);
}
/**
* {@inheritdoc}
*
* Overridden in order to pass in the string date flag.
*/
public function getDateFormat($format) {
return $this->query
->getDateFormat($this->getDateField(), $format, TRUE);
}
}
Classes
Title | Deprecated | Summary |
---|---|---|
Date | Basic sort handler for datetime fields. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.