Development

Sort “Select an existing field” options in Drupal by Label instead of Type

Normally Drupal sorts the “Select an existing field” select list by the field types. Here’s an example of what this looks like:

2016-04-22_11-40-52

This looks good at first glance, but often it’s hard to quickly find the field you want to reuse. Most of the time you’re scanning the list for the name (label) of the field you want to reuse. Wouldn’t it make more sense to put the field label at the beginning and sort by that? I thought it would, so I made it happen with a quick userscript.

I was going to write some Drupal module code to do this, but I wanted it to be available on any Drupal site (because we manage and create lots of them) that I’m developing/editing. Another reason for doing it with a userscript is that it doesn’t affect other users who may prefer the default Drupal output.

I wrote this for/with Tampermonkey in Chrome. I’m sure it’s not the best solution, and my javascript skills could use some work, but it gets the job done. I will cleanup the regex to cover field_ and body, because there’s an awful lot of duplicate code there.

Here’s the same list, with this userscript enabled:

2016-04-22_11-41-41

Leave a Reply

Your email address will not be published.