When source for machine name fields ends with a non-alphanumeric character it is replaced with underscore(_). This looks terrible in case such character is the last one. I think machine name logic should just remove such character in this case.
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | interdiff12-14.txt | 685 bytes | anish.a |
| #15 | machine-name-replacement-character-2229589-15.patch | 4.78 KB | anish.a |
Comments
Comment #1
lahoosascoots commentedGave it a whack.
Made it not be able to start or end with the replacement character.
May want to add a trim($text, $replacement) to the transliterate function in Drupal\system\MachineNameController if we want it to automatically remove the character for you.
Comment #2
mile23This behavior has moved to
Drupal\Core\Render\Element\MachineName::validateMachineName(), so it needs a reroll if it's still desired.Comment #3
djevans commentedRe-rolled patch for 8.0-beta15.
Comment #4
biguzis commentedHere is patch that automatically removes replacement character at machine names beginning and end.
So now if you call your field
+something+machine name wont be anymorefield__something_, but cleanfield_somethingComment #5
martins.kajins commented#4 patch works
Comment #8
marvil07 commentedI would say that both of the last two patches are complementary: one is acting on transliteration, and the other on validation; making the change more consistent in the end.
I also see that both of the patches still apply correctly, but I am requesting a re-roll to unify them in one patch.
Also, there is minor needed change on second patch comments: they need to start with a capital letter and end with a period.
But I would say that the second patch part can be re-written to use
trim()instead, so it is done in one pass, and multiple characters case is also handled.Finally, this needs a related test.
Comment #9
Anonymous (not verified) commentedComment #10
biguzis commentedMerged #3 and #4 patches and added some tests.
Comment #12
biguzis commentedChanged expected value in MachineNameTest as underscore shouldn't be there anymore.
Comment #14
Anonymous (not verified) commentedWell. One of my friends uses an underscore to private, temp, blank, and test entities (_secret, _test, _temp, _default_, _blank_). Another friends just like underscore for amazing smile names (_ll_, _ii_, __oo__, _w_, _qllq_, ...). Why would you want to deprive them of this possibility. Maybe #1643386: Strip useless "_" at beginning and end of JS-transliterated machine names will be enough? If not, please, make it as customizable option. Thanks!
Comment #15
anish.a commentedThere was an unwanted invisible unicode character \u200E. Removed it.
Comment #20
aaronbaumanPersonally, I agree with #14: I would rather not implement this as a validation constraint.
But I would like to see the auto-generated machine-names eliminate preceding and trailing underscores.
This would not only preserve BC, but give flexibility for those who rely on this feature.
Comment #27
xjmMarking wontfix in favor of #1643386: Strip useless "_" at beginning and end of JS-transliterated machine names. Thanks!
Comment #28
xjm