protected function ViewsYearFilterDate::opSimple in Views year filter 8
Overrides Date::opSimple
File
- src/
Plugin/ views/ filter/ ViewsYearFilterDate.php, line 38
Class
- ViewsYearFilterDate
- 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 {
// Add Expression for dates / not timestamp.
$this->query
->addWhereExpression($this->options['group'], "YEAR({$field}) {$this->operator} {$value}");
}
}
else {
parent::opSimple($field);
}
}