Carousel template is throwing error Deprecated function: range(): Passing null to parameter #2 ($end) of type string|int|float is deprecated

Created on 23 September 2024, 3 months ago

Problem/Motivation

When loading the carousel, this error message is popping twice on the screen:

Deprecated function: range(): Passing null to parameter #2 ($end) of type string|int|float is deprecated in __TwigTemplate_4ef0f191370d25f7a2e4bac055c782b9->{closure}() (line 104 of sites/default/files/php/twig/66f19ebdc0765_carousel.macros.twig_30sskPOgOupg__zezzAUx6GAc/1vSx6WzVXtVrrYEq2pDSN2WHgACVvB2k2_5l9aVkMBM.php).

File name 1vSx6WzVXtVrrYEq2pDSN2WHgACVvB2k2_5l9aVkMBM.php is the compiled PHP version of the TWIG template, and the comments within the code help us find the culprit among the module's templates: carousel.macros.twig, which is available within tempaltes/ui-kit/carousel.

The problem boils down to this line: {% for i in 1..numItems %}.

Steps to reproduce

The problem is apparently triggered when running the code on top of PHP v8.3. Just install the module and open the /ui-kit page in a box running PHP 8.3.

Proposed resolution

Replace code {% for i in 1..numItems %} with something that doesn't depend on the numItems variable. This variable is declared here, but never actually used in the template file, so I assume the developer's original idea was to pass the number of slides in the carousel as a parameter. I am thus adding 3 as a default parameter in the suggested change.

Remaining tasks

Review the code I will be providing.

User interface changes

No user interface changes as a result of this change, just an error message that ceases to be printed on the screen.

API changes

No API changes.

Data model changes

No data model changes.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇧🇷Brazil mabho Rio de Janeiro, RJ

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024