Skip to content
Snippets Groups Projects

Issue #3452355 by andileco: Make filter selector and sort selector based on the headers

2 files
+ 28
2
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -4,6 +4,7 @@ namespace Drupal\views_csv_source\Plugin\views\filter;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\filter\FilterPluginBase;
use Drupal\views_csv_source\Plugin\views\query\ViewsCsvQuery;
/**
* Base filter handler for views_csv_source.
@@ -223,10 +224,22 @@ class ViewsCsvFilter extends FilterPluginBase {
$form['key'] = [
'#title' => $this->t('Column Selector'),
'#description' => $this->t('Choose a column'),
'#type' => 'textfield',
'#default_value' => $this->options['key'],
'#required' => TRUE,
];
// Get the query.
$query = $this->view->query;
assert($query instanceof ViewsCsvQuery, 'Query must be of type ViewsCsvQuery');
// Ensure the query is of the correct type.
if ($headers = $query->getCsvHeader()) {
$form['key']['#type'] = 'select';
$form['key']['#options'] = array_combine($headers, $headers);
}
else {
// Fall back to text value if CSV has not been selected.
$form['key']['#type'] = 'textfield';
}
}
/**
Loading