Private message form breaks when there is a validation error

Created on 8 April 2024, 9 months ago
Updated 7 September 2024, 4 months ago

Problem/Motivation

If the message form on /private-messages/x is submitted empty this will lead to a validation error as this field is required. But instead of a validation error message shown on the page, an InvalidQueryExceotion is thrown

Drupal\Core\Database\InvalidQueryException: Query condition 'private_message_thread__private_messages.private_messages_target_id IN ()' cannot be empty. in Drupal\Core\Database\Query\Condition->condition() (line 106 of core/lib/Drupal/Core/Database/Query/Condition.php).

Steps to reproduce

- Enable the Private Message module
- Configure the Private Message module and make sure ajax is used
- Send a message from user A to user B
- Open the message as user B
- Submit the message form without entering a message

Proposed resolution

The problem here is that Private Message tries to load the message thread to add a new message form after submission (see \Drupal\private_message\Form\PrivateMessageForm::ajaxCallback(). It does this by using the ID from the newly added message. But when a validation error occurs, no message is added yet.

Probably no new message form should be added to the page if validation failed. So if the form state has errors in the ajax callback we can return early.

Remaining tasks

-
- Review MR
- Merge MR

User interface changes

N/A

API changes

N/A

Data model changes

N/A

πŸ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

πŸ‡³πŸ‡±Netherlands ricovandevin

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024