Call to a member function get() on null in private_message_form_user_form_alter()

Created on 26 April 2023, about 1 year ago
Updated 28 April 2023, about 1 year ago

Problem/Motivation

Private messaging fields used on the user create admin form. When this form is saved it triggers an error because $user_data is NULL.

There is this if statement:

// Try to fetch user's settings if it is not a registration form.
    if ($user->id()) {
   }

However, outside of that there are two method calls to get methods on $user_setting when $user->id is NULL so it doesn't go into the if statement to set $user_data but still goes on to call $user_data get methods.

Steps to reproduce

Save user registration form:

Call to a member function get() on null in private_message_form_user_form_alter() (line 324 of modules/contrib/private_message/private_message.module).

Call to a member function get() on null in private_message_form_user_form_alter() (line 356 of modules/contrib/private_message/private_message.module).

Proposed resolution

Check if $user_data is set before trying to access get method.

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇺🇸United States wstocker

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024