Skip to content
Snippets Groups Projects
Commit 8d73ab13 authored by Michael Caldwell's avatar Michael Caldwell
Browse files

Issue #3183616: Invert List of Year from recent to older in the Year Views dropdown

parent 1f1767b0
No related branches found
No related tags found
No related merge requests found
......@@ -5,3 +5,12 @@ views.filter.year_field:
reduce_duplicates:
type: boolean
label: 'Reduce duplicate'
year_from:
type: string
label: 'Start year'
year_to:
type: string
label: 'End year'
sort_order:
type: string
label: 'Sort order'
......@@ -24,6 +24,12 @@ class YearField extends ManyToOne {
// Set the options based on extra settings.
$range = range($this->calculateYear($this->options['year_from']), $this->calculateYear($this->options['year_to']));
// Reverse the sort order if needed.
if ($this->options['sort_order'] == 'desc') {
$range = array_reverse($range, TRUE);
}
$this->valueOptions = array_combine($range, $range);
}
......@@ -64,6 +70,7 @@ class YearField extends ManyToOne {
$options = parent::defineOptions();
$options['year_from'] = ['default' => '-30 years'];
$options['year_to'] = ['default' => '+15 years'];
$options['sort_order'] = ['default' => 'asc'];
return $options;
}
......@@ -85,7 +92,7 @@ class YearField extends ManyToOne {
$form['year_from'] = [
'#type' => 'textfield',
'#title' => $this->t('From Year'),
'#title' => $this->t('From year'),
'#required' => TRUE,
'#default_value' => $this->options['year_from'],
'#description' => $this->t("Enter a starting year"),
......@@ -94,12 +101,24 @@ class YearField extends ManyToOne {
$form['year_to'] = [
'#type' => 'textfield',
'#title' => $this->t('To Year'),
'#title' => $this->t('To year'),
'#required' => TRUE,
'#default_value' => $this->options['year_to'],
'#description' => $this->t("Enter an end year."),
'#weight' => 2,
];
$form['sort_order'] = [
'#type' => 'radios',
'#title' => $this->t('Sort order'),
'#required' => TRUE,
'#default_value' => $this->options['sort_order'],
'#options' => [
'asc' => $this->t('Ascending'),
'desc' => $this->t('Descending'),
],
'#weight' => 2,
];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment