Allow bundle fields to be sorted in views tables

This commit is contained in:
Paul Weidner 2023-09-07 11:29:05 -07:00 committed by Michael Stenta
parent 6a0e27914f
commit c05875f9f3
1 changed files with 6 additions and 0 deletions

View File

@ -253,6 +253,7 @@ function farm_ui_views_add_bundle_handlers(ViewExecutable $view, string $display
// Build field options for the field type.
$field_options = [];
$sort_order = 'asc';
// Get the field label.
$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.
$field_options['type'] = 'timestamp';
$field_options['settings']['date_format'] = 'html_date';
// Sort timestamps descending so new dates are on top by default.
$sort_order = 'desc';
break;
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.
$view->getStyle()->options['columns'][$new_field_id] = $new_field_id;
$view->getStyle()->options['info'][$new_field_id] = [
'sortable' => TRUE,
'default_sort_order' => $sort_order,
'align' => '',
'separator' => '',
'empty_column' => TRUE,