Same name in this branch
  1. 10 core/lib/Drupal/Core/Render/Element/Date.php \Drupal\Core\Render\Element\Date
  2. 10 core/modules/datetime/src/Plugin/views/filter/Date.php \Drupal\datetime\Plugin\views\filter\Date
  3. 10 core/modules/datetime/src/Plugin/views/sort/Date.php \Drupal\datetime\Plugin\views\sort\Date
  4. 10 core/modules/views/src/Plugin/views/filter/Date.php \Drupal\views\Plugin\views\filter\Date
  5. 10 core/modules/views/src/Plugin/views/sort/Date.php \Drupal\views\Plugin\views\sort\Date
Same name and namespace in other branches
  1. 8.9.x core/modules/views/src/Plugin/views/sort/Date.php \Drupal\views\Plugin\views\sort\Date
  2. 9 core/modules/views/src/Plugin/views/sort/Date.php \Drupal\views\Plugin\views\sort\Date

Hierarchy

Expanded class hierarchy of Date

1 file declares its use of Date
Date.php in core/modules/datetime/src/Plugin/views/sort/Date.php
23 string references to 'Date'
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.
DbLogTest::testDbLog in core/modules/dblog/tests/src/Functional/DbLogTest.php
Tests Database Logging module functionality through interfaces.

... See full list

File

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

Namespace

Drupal\views\Plugin\views\sort
View 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

Namesort descending Modifiers Type Description Overrides
Date::buildOptionsForm public function Basic options for all sort criteria. Overrides SortPluginBase::buildOptionsForm
Date::defineOptions protected function Overrides SortPluginBase::defineOptions
Date::query public function Called to add the sort to a query. Overrides SortPluginBase::query
SortPluginBase::adminSummary public function Display whether or not the sort order is ascending or descending.
SortPluginBase::buildExposeForm public function
SortPluginBase::canExpose public function Determine if a sort can be exposed.
SortPluginBase::defaultExposeOptions public function Provide default options for exposed sorts.
SortPluginBase::getCacheContexts public function The cache contexts associated with this object. Overrides CacheableDependencyInterface::getCacheContexts
SortPluginBase::getCacheMaxAge public function The maximum age for which this object may be cached. Overrides CacheableDependencyInterface::getCacheMaxAge
SortPluginBase::getCacheTags public function The cache tags associated with this object. Overrides CacheableDependencyInterface::getCacheTags
SortPluginBase::showExposeButton public function Shortcut to display the expose/hide button.
SortPluginBase::showSortForm protected function Shortcut to display the value form.
SortPluginBase::sortOptions protected function Provide a list of options for the default sort form.
SortPluginBase::sortSubmit public function
SortPluginBase::sortValidate protected function
SortPluginBase::submitOptionsForm public function Simple submit handler.
SortPluginBase::trustedCallbacks public static function
SortPluginBase::validateExposeForm public function Validate the options form.
SortPluginBase::validateOptionsForm public function Simple validate handler.