form_alter hook check on classes fails in some cases

Created on 23 January 2023, almost 2 years ago

Problem/Motivation

redirect_options includes a form_alter hook which looks for specific classes on the form object in order to decide whether to make changes.

The check for the specific classes assumes that the property holding the classes ($form['#attributes']['class']) is an array. However, this isn't always the case. For example, this core form explicitly sets a string for that value: https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/modules/lan...

Visiting that form with redirect_options enabled causes a fatal error.

Steps to reproduce

1. Set up a fresh Drupal install (10.x or 9.x), and add redirect_options.
2. Enable redirect_options as well as the language module.
3. Visit the path /admin/config/regional/content-language

You will get an error.

Proposed resolution

The current module checks for a class to determine if it should modify the form, but it is easier to specify the forms to be modified directly. This also would allow us to guarantee the structure that is being checked.

Remaining tasks

Attach patch.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States timcosgrove

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

Comments & Activities

Production build 0.71.5 2024