Problem/Motivation

When the maximum length of a text field is set to less than 6 the _text_devel_generate() function will throw an error:
Warning: mt_rand(): max(0) is smaller than min(1) in _text_devel_generate()

This is because the max value is the max_length divided by six, implicitly cast to an int.

Proposed resolution

Use the ceil() function to ensure the division provides a max of at least 1 on max_lengths greater than 0.

Remaining tasks

Patch needs review.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JvE created an issue. See original summary.

JvE’s picture

Status: Active » Needs review

Note that the Drupal 8 version doesn't have this bug.
There it actually moved to drupal core for which I created a separate issue: #2750925: Text item sample generation fails if max length < 3

JvE’s picture

Title: Warning: mt_rand(): max(0) is smaller than min(1) in _text_devel_generate() » Generating field text fails if max length is less than 6
Issue summary: View changes
jimmyko’s picture

Status: Needs review » Reviewed & tested by the community

I can confirm this issue and manually tested the patch. It is working on Drupal 7.52 with devel-7.x-1.5

  • salvis committed 36151ff on 7.x-1.x
    Issue #2750963 by JvE: Generating field text fails if max length is less...
jacob.embree’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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