Accordion: warning triggered on display

Created on 9 October 2023, about 1 year ago
Updated 12 October 2023, about 1 year ago

Problem/Motivation

The website triggers a PHP Warning when displaying the Accordion widget. It also happens in the admin UI after selecting "Boostrap Accordion" as field group widget.

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in include() (line 576 of /drupal/vendor/composer/ClassLoader.php).

include() (Line: 576)
Composer\Autoload\{closure}('/drupal/web/modules/contrib/field_group_bootstrap/src/Plugin/field_group/FieldGroupFormatter/BootstrapAccordion.php') (Line: 427)
Composer\Autoload\ClassLoader->loadClass('Drupal\field_group_bootstrap\Plugin\field_group\FieldGroupFormatter\BootstrapAccordion')
class_exists('Drupal\field_group_bootstrap\Plugin\field_group\FieldGroupFormatter\BootstrapAccordion') (Line: 96)
Drupal\Component\Plugin\Factory\DefaultFactory::getPluginClass('bootstrap_accordion', Array) (Line: 135)
Drupal\field_group\FieldGroupFormatterPluginManager->getDefaultSettings('bootstrap_accordion', 'view') (Line: 500)
field_group_field_overview_submit(Array, Object)

It is probably caused by PHP 8 being pedantic about continue inside switch blocks https://www.php.net/manual/en/control-structures.switch.php :

Note: Note that unlike some other languages, the continue statement applies to switch and acts similar to break. If you have a switch inside a loop and wish to continue to the next iteration of the outer loop, use continue 2.

Steps to reproduce

Select the Accordion widget in the Field Groups admin UI. Save.

Proposed resolution

Update the line 66 of drupal/web/modules/contrib/field_group_bootstrap/src/Plugin/field_group/FieldGroupFormatter/BootstrapAccordion.php from :

            if (!empty($element[$field_name]['#lazy_builder'])) {
              continue;
            }

to :

            if (!empty($element[$field_name]['#lazy_builder'])) {
              continue 2;
            }
πŸ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

πŸ‡«πŸ‡·France mpellegrin

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

Comments & Activities

Production build 0.71.5 2024