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.
I got this warning when devel-generating some menu links
Warning: mt_rand() [function.mt-rand]: max(1) is smaller than min(2) in devel_generate_links() (line 396 of devel/devel_generate/devel_generate.inc
Comment | File | Size | Author |
---|---|---|---|
#8 | warning_mt_rand_menu-1454632-d8-2012_10_12.patch | 1.67 KB | amitgoyal |
#6 | warning_mt_rand_menu-1454632-d8.patch | 1.73 KB | amitgoyal |
Comments
Comment #1
salvisPlease provide a patch to fix this, D8 first.
Comment #2
amitgoyal CreditAttribution: amitgoyal commentedDuplicate of http://drupal.org/node/1691618. Patch has been applied to fix this issue in D7 and D8.
Comment #3
salvisAre you sure this is the same issue?
How can min be 2 (according to the error message) if it's a constant 1?
Comment #4
amitgoyal CreditAttribution: amitgoyal commentedOops, I didn't saw that min(2). Thanks for the comment.
I tested this in D7 and noticed that if I specify 0 or 1 in "Maximum number of characters in menu and menu link names" field then I get following errors,
Warning: mt_rand(): max(1) is smaller than min(2) in devel_generate_menus() (line 364 of /var/www/d7/sites/all/modules/contrib/devel/devel_generate/devel_generate.inc).
Warning: mt_rand(): max(1) is smaller than min(2) in devel_generate_menus() (line 364 of /var/www/d7/sites/all/modules/contrib/devel/devel_generate/devel_generate.inc).
Looks like we need to add validation so that user specify atleast 3 or more characters in menu and menu link names. Please suggest if you want some validation here or something like max(2, $title_length)?
Comment #5
salvisI'd go for a hint in the UI text and the max().
No need for validation as long as we behave predictably.
Comment #6
amitgoyal CreditAttribution: amitgoyal commented@salvis - I have made the required changes based on your inputs. Please find attached patch for D8.
Comment #7
salvis"at least" is two words.
We try to avoid addressing the user directly wherever possible in Drupal, because this doesn't translate well. #description should really just be a description, so please go for something factual like "The minimum length is 2."
@alberto56: We're seeing a #default_value of 12 — have you changed this to 1 in order to get that error? If you deliberately do weird things, then you typically get weird reactions (garbage in, garbage out). We do expect some common sense from our users and don't aspire to make Devel completely fool-proof...
Please test amitgoyal's patch. He said it was for D8, but the testbot validated it for D7, so it should apply just fine in either version.
Comment #8
amitgoyal CreditAttribution: amitgoyal commentedSure @salvis. I have updated the description as suggested.
I also tested the patch on both D7 and D8 and it applied successfully.
Comment #9
sanchi.girotra CreditAttribution: sanchi.girotra commentedI tested this patch in D7 / D8 and it worked fine for me.
Comment #10
salvisThank you, amitgoyal and sanchi.girotra!
Pushed to D8 and D7 -dev.
Comment #11
alberto56 CreditAttribution: alberto56 commentedHi all, thanks for the patch, which works well for me too.
@salvis to answer your question, I did not deliberately try to break the system. What I think happened is that I inadvertently deleted "12" and left the field blank.
The error message gave me no indication as to what happened.
The new behaviour is much better -- I understand that you don't strive to make Devel completely fool-proof, but thanks to everyone for making it a little more fool-proof, which is great for users like me!
Comment #12
salvisThanks for following up, alberto56.
When you report an issue, please try to reproduce it first and include the steps-to-reproduce in your report (or the fact that you weren't able to reproduce it). That'll be a great help and time-saver for everyone involved.