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

Nishant created an issue. See original summary.

nishant’s picture

Status: Needs work » Needs review
StatusFileSize
new614 bytes

I am providing patch for the above issue, Please validate.

raveen_thakur51’s picture

Status: Needs review » Reviewed & tested by the community

@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.

rushikesh raval’s picture

Assigned: nishant » Unassigned

  • Berdir committed a7f1d27d on 8.x-1.x authored by Nishant
    Issue #3393155 by Nishant: Warning: Undefined array key "description" in...
berdir’s picture

Status: Reviewed & tested by the community » Fixed

Committed.

Status: Fixed » Closed (fixed)

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