protected function ViewsYearFilterDate::opBetween in Views year filter 8
Filters by operator between.
Parameters
object $field: The views field.
Overrides Date::opBetween
File
- src/
Plugin/ views/ filter/ ViewsYearFilterDate.php, line 69
Class
- ViewsYearFilterDate
- Date/time views filter.
Namespace
Drupal\views_year_filter\Plugin\views\filterCode
protected function opBetween($field) {
// If year filter selected.
if (!empty($this->value['type']) && $this->value['type'] == 'date_year' && isset($this->value['min']) && isset($this->value['max'])) {
$min = $this->value['min'] ?? 0;
$max = $this->value['max'] ?? 0;
$operator = strtoupper($this->operator);
// In Case of changed, created and published on date is timestamp.
if (strpos($field, '.changed') !== FALSE || strpos($field, '.created') !== FALSE || strpos($field, '.published_at') !== FALSE) {
$this->query
->addWhereExpression($this->options['group'], "YEAR(FROM_UNIXTIME({$field})) {$operator} {$min} AND {$max}");
}
else {
$this->query
->addWhereExpression($this->options['group'], "YEAR({$field}) {$operator} {$min} AND {$max}");
}
}
else {
parent::opBetween($field);
}
}