Ever since Drupal 7, when the Views module became part of core, some of the core administrative UI has been provided by Views.
For example, /admin/content
is provided by /admin/structure/views/view/content
, so site builders can create custom Views displays or change the configuration of the default display. And we can make tables sortable by arbitrary fields:
Check the sortable box to make that column click sortable, and check the default sort radio to determine which column will be sorted by default, if any.
Anyway, that’s Content. But what about Fields, Form Display and Display?
/admin/structure/types/manage/*/fields
is sorted by Label.
I’d like the option to sort by machine name.
But that table is hard-coded in a core module, so I cannot use Views to accomplish this.
Seems like a core patch or hook implementation would be the Drupal Way of doing it.
Looking at the source now:
https://api.drupal.org/api/drupal/core%21modules%21field_ui%21field_ui.module/9.2.x
Looks like there is a template preprocess hook for the field UI table:
/**
* Prepares variables for field UI overview table templates.
*
* Default template: field-ui-table.html.twig.
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing a Form API structure to be
* rendered as a table.
*/
function template_preprocess_field_ui_table(&$variables) {
template_preprocess_table($variables);
}
I guess that implementation would go in a custom admin theme.
How would I change the sort order in a preprocess hook? (Don’t worry about reversing the sort order when I click on the header, as Views would do. For now, I am just curious to know the simplest hard-coded implementation.)