Now that D7 has a dedicated element to handle automatic setting of machine names based on a human-readable value, we should use this feature to set the keys of fields automatically and reduce the number of horribly named "new_123456890" fields out there.

Comments

quicksketch’s picture

Status: Active » Needs review
StatusFileSize
new4.15 KB
new2.74 KB

Here's a set of patches that adds this ability to Drupal 7 and backports some of the changes (including partial validation of form element keys) to Drupal 6. This helps along #497386: Prevent duplicate key names when re-ordering form a little bit, since it's much more likely that you'll end up with duplicate keys if you're just dragging in 10 new textfields. Each time you edit one of the textfields, you'll have to set a label or field key or run into duplicate key errors. In any case, it's still an improvement over a bunch of fields with new_* names.

D6 doesn't get the auto-key functionality, as #type = 'machine_name' didn't exist in Drupal 6.

This patch also makes a few changes to the attachment of behaviors. Previously we were calling Drupal.attachBehaviors() on the form element wrapper, though this had negative consequences of re-attaching behaviors to both the previewed element (good) and the field configuration form (bad). The new approach only affects the necessary part of the form and not everything.

quicksketch’s picture

Status: Needs review » Fixed

Committed to both branches of the project.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.