protected function ViewsYearFilterDatetime::opSimple in Views year filter 8
Override parent method, which deals with dates as integers.
Overrides Date::opSimple
File
- src/
Plugin/ views/ filter/ ViewsYearFilterDatetime.php, line 38
Class
- ViewsYearFilterDatetime
- Date/time views filter.
Namespace
Drupal\views_year_filter\Plugin\views\filterCode
protected function opSimple($field) {
// If year filter selected.
if (!empty($this->value['type']) && $this->value['type'] == 'date_year' && isset($this->value['value']) && filter_var($this->value['value'], FILTER_VALIDATE_INT)) {
// Get the value.
$value = $this->value['value'] ?? '';
// 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})) {$this->operator} {$value}");
}
else {
$this->query
->addWhereExpression($this->options['group'], "YEAR({$field}) {$this->operator} {$value}");
}
}
else {
parent::opSimple($field);
}
}