Problem
Notification box is crashing with this error:
Error: Call to a member function getGroupContentType() on null in /app/html/profiles/contrib/social/modules/social_features/social_activity/social_activity.tokens.inc on line 81 #0 [internal function]: social_activity_tokens('message', Array, Array, Array, Object(Drupal\Core\Render\BubbleableMetadata))
#1 /app/html/core/lib/Drupal/Core/Extension/ModuleHandler.php(403): call_user_func_array('social_activity...', Array)
#2 /app/html/core/lib/Drupal/Core/Utility/Token.php(304): Drupal\Core\Extension\ModuleHandler->invokeAll('tokens', Array)
#3 /app/html/core/lib/Drupal/Core/Utility/Token.php(196): Drupal\Core\Utility\Token->generate('message', Array, Array, Array, Object(Drupal\Core\Render\BubbleableMetadata))
#4 /app/html/profiles/contrib/social/modules/custom/activity_creator/src/ActivityFactory.php(507): Drupal\Core\Utility\Token->replace('<p><a href="[me...', Array, Array)
#5 /app/html/modules/contrib/social_renamer/src/ActivityFactory.php(89): Drupal\activity_creator\ActivityFactory->processTokens(Array, false, Object(Drupal\message\Entity\Message))
#6 /app/html/profiles/contrib/social/modules/custom/activity_creator/activity_creator.module(218): Drupal\social_renamer\ActivityFactory->getMessageText(Object(Drupal\message\Entity\Message))
#7 [internal function]: activity_creator_entity_view(Array, Object(Drupal\activity_creator\Entity\Activity), Object(Drupal\Core\Entity\Entity\EntityViewDisplay), 'notification')
This most likely happens when the group content or group is removed but the activity item/message is still there.
Solution
Make the token handling more defensive.
Instead of just calling methods on the Entity object we should check if Entity is found before doing that.
Comments
Comment #3
jaapjan commentedhttps://github.com/goalgorilla/open_social/pull/1484
Comment #4
royharink commentedReviewed and tested the code change. Outcome works!