Fix error when delete all messages in the thread

Created on 1 February 2023, almost 2 years ago
Updated 24 February 2023, almost 2 years ago

Problem/Motivation

When trying to remove the last message in the thread this error appears:

TypeError: reset(): Argument #1 ($array) must be of type array, bool given in reset() (line 117 of modules/contrib/privatemsg/src/PrivateMsgService.php).
reset() (Line: 117)
Drupal\privatemsg\PrivateMsgService->getThreadParticipantByThreadId() (Line: 84)
Drupal\privatemsg\Form\ViewMessageForm->buildForm()
call_user_func_array() (Line: 531)
Drupal\Core\Form\FormBuilder->retrieveForm() (Line: 278)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 169)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23)
Stack\StackedHttpKernel->handle() (Line: 709)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Steps to reproduce

- Install the Privatemsg module and enable it.
- Try to send a message to any user.
- Try to delete the message.

Proposed resolution

- The error appears because we removed all messages in the thread so we need to redirect the user to /messages when there are no messages in the thread

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇯🇴Jordan Qusai Taha Amman

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

Comments & Activities

Production build 0.71.5 2024