Hello,
When attempting to add a new field to an existing content type, the preprocess_form_element_label
hook is triggered.
In this specific context, the form element does not have an #id
key. I’ve attached a screenshot illustrating the structure of the current element triggering the error.
This leads to the following warning and error:
Warning: Undefined array key "#id" in Drupal\menu_tree\Hook\Hooks->preprocessFormElementLabel() (web/modules/contrib/menu_tree/src/Hook/Hooks.php line 237)
TypeError: str_starts_with(): Argument #1 ($haystack) must be of type string, null given in str_starts_with() (line 237 of web/modules/contrib/menu_tree/src/Hook/Hooks.php)
This stops the form processing and prevents the field from being added.
I'm not sure whether this issue originates directly from this module, or if it's triggered by the interaction with another contributed module or a specific configuration of my site. I haven’t tested it on a minimal setup.
However, as a safeguard, I suggest adding a check to ensure that the #id
key is defined and not null before calling str_starts_with()
.
I’m currently using:
- Menu Tree module version: 2.1.0
- Drupal core version: 11.2.2
I’ve attached a patch that resolves the issue in my case.
Thanks!