Date.php in Zircon Profile 8.0
Same filename in this branch
- 8.0 vendor/symfony/validator/Constraints/Date.php
- 8.0 vendor/easyrdf/easyrdf/lib/EasyRdf/Literal/Date.php
- 8.0 core/lib/Drupal/Core/Render/Element/Date.php
- 8.0 core/modules/views/src/Plugin/views/filter/Date.php
- 8.0 core/modules/views/src/Plugin/views/sort/Date.php
- 8.0 core/modules/views/src/Plugin/views/argument/Date.php
- 8.0 core/modules/views/src/Plugin/views/field/Date.php
- 8.0 core/modules/datetime/src/Plugin/views/filter/Date.php
- 8.0 core/modules/datetime/src/Plugin/views/sort/Date.php
- 8.0 core/modules/datetime/src/Plugin/views/argument/Date.php
Same filename and directory in other branches
Contains \Drupal\views\Plugin\views\sort\Date.
Namespace
Drupal\views\Plugin\views\sortFile
core/modules/views/src/Plugin/views/sort/Date.phpView source
<?php
/**
* @file
* Contains \Drupal\views\Plugin\views\sort\Date.
*/
namespace Drupal\views\Plugin\views\sort;
use Drupal\Core\Form\FormStateInterface;
/**
* Basic sort handler for dates.
*
* This handler enables granularity, which is the ability to make dates
* equivalent based upon nearness.
*
* @ViewsSort("date")
*/
class Date extends SortPluginBase {
protected function defineOptions() {
$options = parent::defineOptions();
$options['granularity'] = array(
'default' => 'second',
);
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['granularity'] = array(
'#type' => 'radios',
'#title' => $this
->t('Granularity'),
'#options' => array(
'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']);
}
}