You are here

protected function ViewsSearchApiYearFilterDate::opSimple in Views year filter 8

Filters by a simple operator (=, !=, >, etc.).

Parameters

string $field: The views field.

Overrides SearchApiDate::opSimple

File

src/Plugin/views/filter/ViewsSearchApiYearFilterDate.php, line 50

Class

ViewsSearchApiYearFilterDate
Date/time views filter.

Namespace

Drupal\views_year_filter\Plugin\views\filter

Code

protected function opSimple($field) {

  // If year filter selected.
  if (!empty($this->value['type']) && $this->value['type'] == 'date_year' && isset($this->value['value'])) {

    // Get the value.
    $startDate = intval($this->value['value']) . '-01-01 00:00:01';
    $endDate = intval($this->value['value']) . '-12-31 23:59:59';
    $this
      ->getQuery()
      ->addCondition($this->realField, [
      strtotime($startDate),
      strtotime($endDate),
    ], 'BETWEEN', $this->options['group']);
  }
  else {
    parent::opSimple($field);
  }
}