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

Created on 14 November 2023, about 1 year ago
Updated 11 July 2024, 5 months ago

Problem/Motivation

Steps to reproduce

If a user subscribes to a forum post then delete that post. Accessing the user edit page causes the following server error:

The website encountered an unexpected error. Please try again later.

Error: Call to a member function get() on null in getForumName() (line 655 of modules/contrib/forum_notifications_subscription/forum_notifications_subscription.module).

forum_notifications_subscription_form_alter(Array, Object, 'user_form') (Line: 545)
Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object, 'user_form') (Line: 840)
Drupal\Core\Form\FormBuilder->prepareForm('user_form', Array, Object) (Line: 284)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 592)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Proposed resolution

Deleting a watched entity should delete its corresponding record in forum_notification_frequency table

๐Ÿ› Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States abu3antar

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

Merge Requests

Comments & Activities

  • Issue created by @abu3antar
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia chetan 11

    chetan 11 โ†’ made their first commit to this issueโ€™s fork.

  • Merge request !2fixed โ†’ (Open) created by chetan 11
  • Status changed to Needs review about 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia chetan 11

    Hi,
    I have fixed the above error on my local setup, please check the attached MR once.
    Thanks.

  • Status changed to Needs work 8 months ago
  • ๐Ÿ‡ธ๐Ÿ‡ณSenegal diaodiallo

    Hi Chetan, thanks for working on this.
    After quick review of this I think we need not just to return a default name but also do more i.e about the frequency around that post.

  • arora.shivani โ†’ made their first commit to this issueโ€™s fork.

  • Status changed to Needs review 8 months ago
  • Hello,
    I have created a patch for it , Please review. I am not able to push the code from my new branch due to restricted access rights.
    Thank you!

  • Status changed to Needs work 8 months ago
  • ๐Ÿ‡ธ๐Ÿ‡ณSenegal diaodiallo

    I actually think the work around this should focus on the deletion process.
    #1 Someone remove a post.
    #2 A hook (something like hook_ENTITY_TYPE_delete()) check if this node id has a forum_notification_frequency (this nid means the entity_id of the frequency)
    #3 If That forum_notification_frequency exists it removes it.

    Here is the Entity definition itself

    Here is how to get notification by id

    So should implement the same thing to get notification by subscribed entity id (entity_id) in the ForumNotificationsSubscriptionService class.

    After finding it we should delete it so we will no longer fall on it when looping frequencies in the user_form.

    Please let me know if someone want to work on this or if there is any need for clarification.

  • ๐Ÿ‡ธ๐Ÿ‡ณSenegal diaodiallo
Production build 0.71.5 2024