You are here

public function DateRange::init in Views Contextual Range Filter 8

Overrides Drupal\views\Plugin\views\argument\Formula::init().

Overrides Formula::init

File

src/Plugin/views/argument/DateRange.php, line 25

Class

DateRange
Argument handler to accept a date range.

Namespace

Drupal\contextual_range_filter\Plugin\views\argument

Code

public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
  parent::init($view, $display, $options);
  switch ($options['id']) {
    case 'changed_year':
    case 'created_year':
      $this->format = 'Y';
      $this->argFormat = 'Y';
      break;
    case 'changed_year_month':
    case 'created_year_month':
      $this->format = 'F Y';
      $this->argFormat = 'Ym';
      break;
    case 'changed_month':
    case 'created_month':
      $this->format = 'F';
      $this->argFormat = 'm';
      break;
    case 'changed_week':
    case 'created_week':
      $this->format = 'w';
      $this->argFormat = 'W';
      break;
    case 'changed_day':
    case 'created_day':
      $this->format = 'j';
      $this->argFormat = 'd';
      break;

    // 'changed':
    // 'changed_fulldate':
    // 'created':  // for nodes and users
    // 'created_fulldate':
    // ... and everything else.
    default:
      $this->format = 'F j, Y';

      // argFormat used to be 'Ymd'. However in D8 when a plain Context Filter
      // is used for a timestamp or a DateTime the default format is 'Y-m-d'.
      // This is also the format used by MySQL.
      // Should we allow an optional appended time-of-day, eg 'Y-m-d H:i:s'?
      // This would clash with the alternative range operator ':'.
      $this->argFormat = 'Y-m-d';
      break;
  }
}