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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

salvis’s picture

Status: Active » Needs work

Please provide a patch to fix this, D8 first.

amitgoyal’s picture

Status: Needs work » Fixed

Duplicate of http://drupal.org/node/1691618. Patch has been applied to fix this issue in D7 and D8.

salvis’s picture

Are you sure this is the same issue?

How can min be 2 (according to the error message) if it's a constant 1?

amitgoyal’s picture

Status: Fixed » Active

Oops, 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)?

salvis’s picture

I'd go for a hint in the UI text and the max().

No need for validation as long as we behave predictably.

amitgoyal’s picture

Assigned: Unassigned » amitgoyal
Status: Active » Needs review
FileSize
1.73 KB

@salvis - I have made the required changes based on your inputs. Please find attached patch for D8.

salvis’s picture

Status: Needs review » Needs work
+++ b/devel_generate/devel_generate.module
@@ -436,6 +436,7 @@ function devel_generate_menu_form() {
+    '#description' => t("Please specify atleast 2 or more number of characters for suitable menu and menu link names."),
     '#default_value' => 12,

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

amitgoyal’s picture

Status: Needs work » Needs review
FileSize
1.67 KB

Sure @salvis. I have updated the description as suggested.

I also tested the patch on both D7 and D8 and it applied successfully.

sanchi.girotra’s picture

Status: Needs review » Reviewed & tested by the community

I tested this patch in D7 / D8 and it worked fine for me.

salvis’s picture

Assigned: amitgoyal » Unassigned
Status: Reviewed & tested by the community » Fixed

Thank you, amitgoyal and sanchi.girotra!

Pushed to D8 and D7 -dev.

alberto56’s picture

Hi 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!

salvis’s picture

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

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.