Problem/Motivation
Warning: Undefined array key "description" in token_node_menu_link_submit() (line 741 of modules/contrib/token/token.module)
Deprecated function: trim(): Passing null to parameter #1 ($string) of type string is deprecated in token_node_menu_link_submit() (line 741 of modules/contrib/token/token.module).
Steps to reproduce
Install 'token' module and try to create a node or edit the existing node of any node type.
I am using Drupal Version - 10.1.5, and PHP Version - 8.1.21
Proposed resolution
Add this line $entity->description->value = trim($values['description'] ?? '');
instead of $entity->description->value = trim($values['description']);
Remaining tasks
User interface changes
API changes
Data model changes
Comments
Comment #2
nishantI am providing patch for the above issue, Please validate.
Comment #3
raveen_thakur51 commented@Nishant,
I have reviewed your code in the patch, it checks if $values['description'] is set, and if it's not set (null or undefined), it assigns an empty string as a default value. This is done to prevent the deprecated warning when trim is applied to a null value.
It's a good practice to handle potentially missing or null values to prevent unexpected issues in code.
Can be moved to RTBC++
And Thank you for your work.
Comment #4
rushikesh raval commentedComment #6
berdirCommitted.