What the title says.

Original report:

Problem/Motivation

In the configuration form (/admin/config/people/saml), when save the form. The following PHP warning message occured.

Warning: Undefined array key "#default_value" in Drupal\samlauth\Element\MultiValue::processMultiValue() (line 190 of modules/contrib/samlauth/src/Element/MultiValue.php).

Steps to reproduce

  1. Install this module in a Drupal 10 website which is running with PHP 8.1
  2. Go to the configuration form (/admin/config/people/saml)>/li>
  3. Fill in all mandatory fields in the form.
  4. Save the form.

Proposed resolution

Change the line at 190 in src/Element/MultiValue.php
from

if (!$element['#default_value'] && isset($element['#add_empty']) && $element['#add_empty'] === FALSE) {

to

if (empty($element['#default_value']) && isset($element['#add_empty']) && $element['#add_empty'] === FALSE) {
CommentFileSizeAuthor
#5 Patchfile.patch1.13 KBvishal choudhary

Issue fork samlauth-3352286

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Mingsong created an issue. See original summary.

mingsong’s picture

Status: Active » Needs review
mingsong’s picture

Issue summary: View changes
vishal choudhary’s picture

StatusFileSize
new1.13 KB

I have added a new patch to fixed these errors.

  • roderik committed f066922c on 8.x-3.x authored by Mingsong
    Issue #3352286 by Mingsong: Warning message in Drupal 10 with PHP 8.1
    
roderik’s picture

Status: Needs review » Needs work

Checked both patches. Tested. Patch #5 is wrong: $element['#default_value'] is an empty array on initial form load, so introducing !isset() changes behavior. (The screen shows 0 empty elements.) It also has unwanted whitespace changes.

I'm committing this, but not closing the issue, because there is more to do here:

  • The class' comment says:
     * Shamelessly copied from multivalue_form_element, on who we'll depend in 4.x.
     * (At the time of adding this, they seemed to have issues with D9
     * compatibility.)
    
  • The changed code is not from the MultiValue.php currently commited in multivalue_form_element, but from a patch I made: #3199298: Don't add an empty element in some cases. This patch is now
    • outdated, because the change from this issue is not propagated into #3199298
    • outdated according to comment #3199298-8: Don't add an empty element in some cases ($max should not occur anywhere in the code, so the patch likely should be rerolled)
    • still not going to be merged because it's missing tests
    • possibly complicated by the fact that I built my patch on another needs-review patch: if we add tests, we might need to split those two issues up again, for the reviewer.

This issue remains open to at least unify our own MultiValue.php with the patch, so that we don't lose any changes when we start depending on multivalue_form_element. (Or to track that we don't lose changes, in another way.)

roderik’s picture

Title: Warning message in Drupal 10 with PHP 8.1 » Keep MultiValue.php synchronized with upstream
Issue summary: View changes

  • roderik committed f066922c on 4.x authored by Mingsong
    Issue #3352286 by Mingsong: Warning message in Drupal 10 with PHP 8.1
    

joelpittet made their first commit to this issue’s fork.

joelpittet’s picture

Status: Needs work » Fixed

This looks fixed from #9

Status: Fixed » Closed (fixed)

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