Allow bundle fields to be sorted in views tables
This commit is contained in:
parent
6a0e27914f
commit
c05875f9f3
|
@ -253,6 +253,7 @@ function farm_ui_views_add_bundle_handlers(ViewExecutable $view, string $display
|
||||||
|
|
||||||
// Build field options for the field type.
|
// Build field options for the field type.
|
||||||
$field_options = [];
|
$field_options = [];
|
||||||
|
$sort_order = 'asc';
|
||||||
|
|
||||||
// Get the field label.
|
// Get the field label.
|
||||||
$field_options['label'] = $field_definition->getLabel();
|
$field_options['label'] = $field_definition->getLabel();
|
||||||
|
@ -264,6 +265,9 @@ function farm_ui_views_add_bundle_handlers(ViewExecutable $view, string $display
|
||||||
// Render timestamp fields in the html_date format.
|
// Render timestamp fields in the html_date format.
|
||||||
$field_options['type'] = 'timestamp';
|
$field_options['type'] = 'timestamp';
|
||||||
$field_options['settings']['date_format'] = 'html_date';
|
$field_options['settings']['date_format'] = 'html_date';
|
||||||
|
|
||||||
|
// Sort timestamps descending so new dates are on top by default.
|
||||||
|
$sort_order = 'desc';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'boolean':
|
case 'boolean':
|
||||||
|
@ -307,6 +311,8 @@ function farm_ui_views_add_bundle_handlers(ViewExecutable $view, string $display
|
||||||
// Add the field to the table style options.
|
// Add the field to the table style options.
|
||||||
$view->getStyle()->options['columns'][$new_field_id] = $new_field_id;
|
$view->getStyle()->options['columns'][$new_field_id] = $new_field_id;
|
||||||
$view->getStyle()->options['info'][$new_field_id] = [
|
$view->getStyle()->options['info'][$new_field_id] = [
|
||||||
|
'sortable' => TRUE,
|
||||||
|
'default_sort_order' => $sort_order,
|
||||||
'align' => '',
|
'align' => '',
|
||||||
'separator' => '',
|
'separator' => '',
|
||||||
'empty_column' => TRUE,
|
'empty_column' => TRUE,
|
||||||
|
|
Loading…
Reference in New Issue