function Date::query

Same name in other branches
  1. 8.9.x core/modules/views/src/Plugin/views/sort/Date.php \Drupal\views\Plugin\views\sort\Date::query()
  2. 10 core/modules/views/src/Plugin/views/sort/Date.php \Drupal\views\Plugin\views\sort\Date::query()
  3. 11.x core/modules/views/src/Plugin/views/sort/Date.php \Drupal\views\Plugin\views\sort\Date::query()

Called to add the sort to a query.

Overrides SortPluginBase::query

1 method overrides Date::query()
StatisticsLastUpdated::query in core/modules/comment/src/Plugin/views/sort/StatisticsLastUpdated.php
Called to add the sort to a query.

File

core/modules/views/src/Plugin/views/sort/Date.php, line 47

Class

Date
Basic sort handler for dates.

Namespace

Drupal\views\Plugin\views\sort

Code

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']);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.