Activity: Undefined array key "#view_mode"

Created on 3 June 2024, 26 days 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.69.0 2024