Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
It's a follow-up from #1813832: Entity wrongly checks existence of ID in isNew() method
Problem/Motivation
Currently machine-readable names allows to use '0' (string zero) for value
Mostly all of config entities use machine names as id()
Proposed resolution
Disallow usage of '0' as machine-name:
- fix machine name element and validator
- add tests
Comments
Comment #1
fagoI think we should disallow machine names starting which a number in general, afaik those are not valid PHP variable names either.
Comment #2
sunI guess #1 makes sense.
Baking this into the PCREs being used by the validation might be non-trivial though.
Comment #3
xjmYeah, I was thinking along the lines of #1 actually when discussing this with @andypost; 0 just seemed like the most obviously bad case. I checked and randomName() already enforces that the machine names start with a letter.
Comment #8
th_tushar CreditAttribution: th_tushar as a volunteer commentedShould be a workaround to make it work as a content entity.