Activity: Undefined array key "#view_mode"

Created on 3 June 2024, 7 months ago

Problem/Motivation

Undefined array key "#view_mode" in template_preprocess_activity() (line 54 of profiles/contrib/open_social/modules/custom/activity_creator/activity.page.inc)

I got a lot of these warnings when viewing acitivties in streams.

Problem comes from this if:

if (isset($variables['elements']['#view_mode']) && in_array($variables['content']['field_activity_output_text']['#view_mode'], [
  'notification',
  'notification_archive',
])) {
  ...
}

Asking for $variables['content']['field_activity_output_text']['#view_mode'] in in_array method makes no sense, because field_activity_output_text is a text field and therefore has no view mode.

Proposed resolution

Ask for elements view mode in in_array method:

if (isset($variables['elements']['#view_mode']) && in_array($variables['elements']['#view_mode'], [
  'notification',
  'notification_archive',
])) {
  ...
}
🐛 Bug report
Status

Needs review

Version

12.0

Component

Activity/Notifications

Created by

🇩🇪Germany Duwid

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

Comments & Activities

Production build 0.71.5 2024