Machine name form element should allow prefix and suffix

Created on 9 April 2014, over 10 years ago
Updated 6 July 2023, about 1 year ago

I think #machine_name form element should allow user/develoepr to set prefix and suffix for the resulting name.
For exmaple if the value of the source is 'This is test' then the resulting machine name would be 'this_is_test'.
If I'd add prefix 'so' then the resulting machine name would be 'so_this_is_test'. If I'd add 'yo' suffix then the resulting machine name would be 'so_this_is_test_yo'. If however 'so_this_is_test_yo' would already exist then the new unique name would be 'so_this_is_test1_yo' and NOT 'so_this_is_test_yo1' since the prefix and sufix values should be preserved.

Feature request
Status

Active

Version

10.1

Component
Form 

Last updated 1 minute ago

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇫🇷France gabesullice 🇫🇷 ①③ UTC+2

    A gaunt hand breaks through the damp earth of the cemetery grounds, once dead, the zombie (issue) rises to torment us again.

    heh, jokes aside. I stumbled in here because I came across a similar need. @tim.plunkett, you're right that you can make this work with the form system as-is, but one needs to customize the validateForm method and call setValueForElement() method. So yes, it's already possible, but only if you have a deep enough understanding of the form API to understand what's going on in FieldStorageAddForm and are willing to set data during the validation step.

    I think it's a reasonable feature request to make this part of the machine name form element API via a #value_prefix property or similar. Perhaps as a #process callback. I guess that's why this issue hasn't ever been closed.

    Maybe this bump will breath new life into the idea ;)

  • 🇫🇷France gabesullice 🇫🇷 ①③ UTC+2
Production build 0.71.5 2024