Problem/Motivation
When Comment Notify loads the comment form, it retrieves the current user’s comment_notify preference.
The module assumes that a user with stored Comment Notify settings has both entity_notify and comment_notify values. However, users can have only entity_notify stored. In that case, UserNotificationSettings::getSetting() attempts to access a missing array key and PHP emits:
Warning: Undefined array key "comment_notify" in src/UserNotificationSettings.php
This was observed while users reviewed unpublished Article content with an enabled comment field.
Steps to reproduce
- Install Comment Notify 8.x-1.5.
- Enable Comment Notify for an entity bundle with a comment field.
- Create a user with permission to subscribe to comments.
- Store only an
entity_notifypreference for that user, without storingcomment_notify. - Visit content where the enabled comment form is displayed as that user.
For example, the incomplete preference state can be created with:
$user_settings->saveSettings($uid, COMMENT_NOTIFY_ENTITY);
Proposed resolution
When a stored settings array does not contain the requested preference, merge the configured default settings before returning the requested value.
This preserves explicitly stored preferences and uses the configured default only for the missing key.
The attached patch:
- Updates
src/UserNotificationSettings.phpto apply defaults for an individual missing preference. - Adds a functional regression test for a user with only
entity_notifystored.
Remaining tasks
- Review and test the attached patch.
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 3612852-6.patch | 1.65 KB | gnuget |
| #2 | comment_notify-missing-preference-3612852-2.patch | 1.35 KB | jwilson3 |
Issue fork comment_notify-3612852
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jwilson3Comment #5
gnugetI moved the fallback to
UserNotificationSettings::getSettings()becausecomment_notify_form_user_form_alter()uses that method directly and the user profile form would otherwise receive a missing value instead of the configured default.Comment #6
gnugetPatch attached.
Comment #8
gnuget