Undefined array key "#cardinality"

Created on 14 February 2024, 9 months ago
Updated 11 March 2024, 9 months ago

Problem/Motivation

Reading the cardinality with the ternary operator ($element['#cardinality'] ?: NULL) without testing beforehand if the array key exists triggers a warning shown as error by Drupal:

Warning: Undefined array key "#cardinality" in Drupal\choices_autocomplete\Element\ChoicesAutocomplete::processChoicesAutocomplete() (line 58 of modules/contrib/choices_autocomplete/src/Element/ChoicesAutocomplete.php).

Proposed resolution

Either use the NULL coalescing operator (which looks quite strange when passing NULL: $element['#cardinality'] ?? NULL) or explicitly check with isset().

πŸ› Bug report
Status

RTBC

Version

1.3

Component

Code

Created by

πŸ‡¦πŸ‡ΉAustria mvonfrie

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