This is a sub-part of the larger patch proposed here: http://drupal.org/node/88633
Go ahead- I dare you. Create a new node type and give it the machine-readable name 0 (just the number zero).
This problem occurs because the validation for "required" form values allows the string '0', but in PHP empty('0') == TRUE, so all the checks for empty() (or not empty()) $type->type values don't work.
Attached patch returns a validation error if the $type->type evaluates to empty. This is the simplest thing I can think of that does not break any existing t() strings.
Comments
Comment #1
Jaza commentedThis is about the simplest solution that we can implement for catching this uncommon edge case. I think that other possible solutions, such as enforcing a minimum length of 2 chars for node type names, is overdoing it.
RTBC.
Comment #2
drummThe error message, "Invalid machine-readable name 0," is not helpful. Why isn't this valid? What can be done to fix it? Why is it 'machine-readable' in the message but the field is labeled 'type'?
Comment #3
pwolanin commentedHere's an improved error message.
Comment #4
pwolanin commentedsince the text seemed to be the only problem, setting back to RTBC
Comment #5
ChrisKennedy commentedThe comment should go on its own line imo.
More importantly, the error message is inaccurate: "Please use a type name with more than one character, or a character other than zero."
As far as I can tell there is no requirement that the type be more than one character. I think you're trying to say that it needs to be at least one character, and also cannot be '0'. However, I this message need only occur if the type is zero itself, because #required is already set to TRUE for $form['identity']['type'], so we know that it isn't a truly empty string. See _form_validate().
If I'm right, the error message should be something like: "Please choose a type name other than '0'." This also suggests that the comment should be modified, and you might as well make the if test be === '0' to be clearer.
Comment #6
pwolanin commentedFYI, in form.inc, the code validating "required" fields in _form_validate() is:
revised patch attached for this annoying edge case.
Comment #7
ChrisKennedy commentedUpdated patch looks good and works as designed.
I hope in d6 we can remove the lazy empty(), etc. checks throughout core that create these edge cases. That is an issue for another day.
Comment #8
drummCommitted to HEAD.
Comment #9
(not verified) commented