Updated: Comment #0
Problem/Motivation
Machine names are by their nature unique, so they typically have validation to ensure a duplicate machine name does not already exist. However, when the machine name is auto-generated based on another field, the user might sometimes create a duplicate machine name without knowing the machine name field even exists. This causes a usability problem when the user is suddenly confronted with an error on a field they've never seen before.
For example, in the field UI:
- Install 8.x standard.
- Go to
admin/structure/types/manage/page/fields
. - Under "Add new field," type "tags" in the Label field and select a term reference field.
- You receive a validation error on a field you did not fill in.
Proposed resolution
Make the machine name element provide the option to automatically append a delta.
- #1998582: Auto-generate machine_name for Views Blocks using [viewname]_[displayname] rather than forcing manual entry does this by adding the delta to the default value. For more typical machine name fields, this would mean that the realtime machine name generation would need to query for existing machine names on each keystroke, which might not be ideal.
- Another option would be to append the delta on save.
Remaining tasks
- Choose an approach.
- Create patch.
- Update existing machine names in the block and field UIs to use the auto-delta.
- Remove the custom delta generation from the views block plugin.
Comments
Comment #0.0
xjmUpdated issue summary.
Comment #1
sdboyer CreditAttribution: sdboyer commentedi think the fact that we have this problem is symptomatic of the fact that we're stitching things together wrong, and we should fix the problem, not the symptom. if we've got forms where we're expecting users to skip a field, then it's absolutely not OK to pre-populate that field with something that could trigger a validation error. that makes it the responsibility of the form controller to ensure that a default is set that will not trigger a validation error - which is what i put into place over in #2022897: Shift responsibility for creating unique config id/machine name off of (views) block plugins and onto BlockFormController.
setting a default value on the machine name field also has the nice side benefit of stopping the machine name field from chasing the contents of the label field. and it seems to me that, if we're on a form where we've prepopulated the field that the machine name attaches itself to, then what we're really saying is that, on that form, we don't WANT to bother the user with having to think about a machine name - an autogenerated one is probably good enough. so there's little value added in having the machine name chase around another value - if the user wants to change it, they can click 'edit'. otherwise, let's get out of their way.
i don't know if the approach taken in #2022897: Shift responsibility for creating unique config id/machine name off of (views) block plugins and onto BlockFormController is applicable to field UI. but the tl;dr on that issue is that i added a method to
BlockPluginInterface
to get a baseline suggestion for a machine name, then left it up toBlockFormController
to ensure the uniqueness of that id.Comment #1.0
sdboyer CreditAttribution: sdboyer commentedUpdated issue summary.