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.

Comments

lahoosascoots’s picture

Status: Active » Needs review
StatusFileSize
new1.57 KB

Gave 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.

mile23’s picture

Status: Needs review » Needs work

This behavior has moved to Drupal\Core\Render\Element\MachineName::validateMachineName(), so it needs a reroll if it's still desired.

djevans’s picture

Status: Needs work » Needs review
StatusFileSize
new1.95 KB

Re-rolled patch for 8.0-beta15.

biguzis’s picture

Here 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 anymore field__something_, but clean field_something

martins.kajins’s picture

#4 patch works

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

marvil07’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs reroll

I 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.

Anonymous’s picture

biguzis’s picture

Status: Needs work » Needs review
StatusFileSize
new4.11 KB
new2.51 KB

Merged #3 and #4 patches and added some tests.

Status: Needs review » Needs work

The last submitted patch, 10: machine-name-replacement-character-2229589-10.patch, failed testing.

biguzis’s picture

Status: Needs work » Needs review
StatusFileSize
new4.78 KB
new3.18 KB

Changed expected value in MachineNameTest as underscore shouldn't be there anymore.

Status: Needs review » Needs work

The last submitted patch, 12: machine-name-replacement-character-2229589-12.patch, failed testing.

Anonymous’s picture

Well. 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!

anish.a’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new4.78 KB
new685 bytes

There was an unwanted invisible unicode character \u200E. Removed it.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

aaronbauman’s picture

Personally, 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.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

xjm’s picture

xjm’s picture

Status: Needs review » Closed (won't fix)
Issue tags: -Needs tests