G2 Random block should warn that it does not work with less than 3 nodes instead of causing an error

Created on 27 November 2011, over 12 years ago
Updated 27 June 2023, about 1 year ago

I put two g2 blocks:G2 Random and G2 Alphabar on frontpage panel (Add content -> Miscellaneous).

Now I've got this error:

Warning: mt_rand() [function.mt-rand]: max(-1) is smaller than min(0) in g2\random() (line 1175 of Z:\home\paris9.kz\www\emploi\sites\all\modules\g2\g2.module).
Notice: Trying to get property of non-object in g2\random() (line 1201 of Z:\home\paris9.kz\www\emploi\sites\all\modules\g2\g2.module).
EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() (line 7389 of Z:\home\paris9.kz\www\emploi\includes\common.inc).

Problem seems to be with Random block.

✨ Feature request
Status

Active

Version

1.0

Component

Miscellaneous

Created by

πŸ‡°πŸ‡ΏKazakhstan clashar

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡«πŸ‡·France fgm Paris, France

    Still happens on D10/D9 with a different location:

    • with just two nodes, if the stored random and the WOTD are different
    • with just one node, if either the stored random the WOTD are that node
    • with no node (d'oh)

    The better UX is probably to just build an empty block and log the issue instead of exposing it to the front user.

Production build 0.69.0 2024