class Date in Drupal 10
Same name in this branch
- 10 core/lib/Drupal/Core/Render/Element/Date.php \Drupal\Core\Render\Element\Date
- 10 core/modules/views/src/Plugin/views/filter/Date.php \Drupal\views\Plugin\views\filter\Date
- 10 core/modules/views/src/Plugin/views/sort/Date.php \Drupal\views\Plugin\views\sort\Date
- 10 core/modules/views/src/Plugin/views/argument/Date.php \Drupal\views\Plugin\views\argument\Date
- 10 core/modules/views/src/Plugin/views/field/Date.php \Drupal\views\Plugin\views\field\Date
- 10 core/modules/datetime/src/Plugin/views/filter/Date.php \Drupal\datetime\Plugin\views\filter\Date
- 10 core/modules/datetime/src/Plugin/views/sort/Date.php \Drupal\datetime\Plugin\views\sort\Date
- 10 core/modules/datetime/src/Plugin/views/argument/Date.php \Drupal\datetime\Plugin\views\argument\Date
Same name and namespace in other branches
- 8 core/modules/views/src/Plugin/views/sort/Date.php \Drupal\views\Plugin\views\sort\Date
- 9 core/modules/views/src/Plugin/views/sort/Date.php \Drupal\views\Plugin\views\sort\Date
Basic sort handler for dates.
This handler enables granularity, which is the ability to make dates equivalent based upon nearness.
Plugin annotation
@ViewsSort("date");
Hierarchy
- class \Drupal\views\Plugin\views\sort\SortPluginBase extends \Drupal\views\Plugin\views\HandlerBase implements CacheableDependencyInterface
- class \Drupal\views\Plugin\views\sort\Date
Expanded class hierarchy of Date
2 files declare their use of Date
- Date.php in core/
modules/ datetime/ src/ Plugin/ views/ sort/ Date.php - StatisticsLastUpdated.php in core/
modules/ comment/ src/ Plugin/ views/ sort/ StatisticsLastUpdated.php
23 string references to 'Date'
- Date::getSortName in core/
modules/ views/ src/ Plugin/ views/ argument/ Date.php - Datetime::processDatetime in core/
lib/ Drupal/ Core/ Datetime/ Element/ Datetime.php - Expands a datetime element type into date and/or time elements.
- DateTimeSchemaTest::testDateTimeSchema in core/
modules/ datetime/ tests/ src/ Kernel/ Views/ DateTimeSchemaTest.php - Tests argument plugin schema.
- DbLogController::eventDetails in core/
modules/ dblog/ src/ Controller/ DbLogController.php - Displays details about a specific database log message.
- DbLogController::overview in core/
modules/ dblog/ src/ Controller/ DbLogController.php - Displays a listing of database log messages.
File
- core/
modules/ views/ src/ Plugin/ views/ sort/ Date.php, line 15
Namespace
Drupal\views\Plugin\views\sortView source
class Date extends SortPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['granularity'] = [
'default' => 'second',
];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['granularity'] = [
'#type' => 'radios',
'#title' => $this
->t('Granularity'),
'#options' => [
'second' => $this
->t('Second'),
'minute' => $this
->t('Minute'),
'hour' => $this
->t('Hour'),
'day' => $this
->t('Day'),
'month' => $this
->t('Month'),
'year' => $this
->t('Year'),
],
'#description' => $this
->t('The granularity is the smallest unit to use when determining whether two dates are the same; for example, if the granularity is "Year" then all dates in 1999, regardless of when they fall in 1999, will be considered the same date.'),
'#default_value' => $this->options['granularity'],
];
}
/**
* Called to add the sort to a query.
*/
public function query() {
$this
->ensureMyTable();
switch ($this->options['granularity']) {
case 'second':
default:
$this->query
->addOrderBy($this->tableAlias, $this->realField, $this->options['order']);
return;
case 'minute':
$formula = $this
->getDateFormat('YmdHi');
break;
case 'hour':
$formula = $this
->getDateFormat('YmdH');
break;
case 'day':
$formula = $this
->getDateFormat('Ymd');
break;
case 'month':
$formula = $this
->getDateFormat('Ym');
break;
case 'year':
$formula = $this
->getDateFormat('Y');
break;
}
// Add the field.
$this->query
->addOrderBy(NULL, $formula, $this->options['order'], $this->tableAlias . '_' . $this->field . '_' . $this->options['granularity']);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Date:: |
public | function |
Basic options for all sort criteria. Overrides SortPluginBase:: |
|
Date:: |
protected | function |
Overrides SortPluginBase:: |
|
Date:: |
public | function |
Called to add the sort to a query. Overrides SortPluginBase:: |
1 |
SortPluginBase:: |
public | function | Display whether or not the sort order is ascending or descending. | |
SortPluginBase:: |
public | function | ||
SortPluginBase:: |
public | function | Determine if a sort can be exposed. | |
SortPluginBase:: |
public | function | Provide default options for exposed sorts. | |
SortPluginBase:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyInterface:: |
|
SortPluginBase:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyInterface:: |
|
SortPluginBase:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyInterface:: |
|
SortPluginBase:: |
public | function | Shortcut to display the expose/hide button. | |
SortPluginBase:: |
protected | function | Shortcut to display the value form. | |
SortPluginBase:: |
protected | function | Provide a list of options for the default sort form. | |
SortPluginBase:: |
public | function | ||
SortPluginBase:: |
protected | function | ||
SortPluginBase:: |
public | function | Simple submit handler. | |
SortPluginBase:: |
public static | function | ||
SortPluginBase:: |
public | function | Validate the options form. | |
SortPluginBase:: |
public | function | Simple validate handler. |