Problem/Motivation

In the user stream page (user/*/stream) I have an error saying
Warning: Illegal string offset '#markup' in social_core_preprocess_block() (line 408 of profiles/contrib/social/modules/social_features/social_core/social_core.module).

Steps to reproduce

Go to user > profile, an error is shown complaining about #Markup

Proposed resolution

Replace actual code (around line 408)

$variables['button_text'] = t('All @label', [
    '@label' => $variables['label']['#markup'],
]);

With

if (isset($variables['label']['#markup'])) {
        $label = $variables['label']['#markup'];
      }
      else {
        $label = t('events');
      }
      $variables['button_text'] = t('All @label', [
        '@label' => $label,
      ]);

Remaining tasks

Creating a patch for this issue

User interface changes

None

API changes

None

Data model changes

None

Issue fork social-3314911

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

dco created an issue. See original summary.

immaculatexavier’s picture

Assigned: Unassigned » immaculatexavier
avpaderno’s picture

Version: 11.4.4 » 11.4.x-dev
immaculatexavier’s picture

Assigned: immaculatexavier » Unassigned
Status: Active » Needs review
StatusFileSize
new842 bytes

Attached patch in accordance to the proposed resolution

avpaderno’s picture

Status: Needs review » Needs work
+        if (isset($variables['label']['#markup'])) {
+          $label = $variables['label']['#markup'];
+        }
+        else {
+          $label = t('events');
+        }

Since PHP 7 is required, that code can be written on a single line, with the null coalescing operator.

pflora’s picture

Status: Needs work » Needs review
StatusFileSize
new772 bytes
new781 bytes

Thank you for your suggestion, @apaderno!

Here's a patch with the requested changes.

avpaderno’s picture

Status: Needs review » Needs work
+
+        $label = $variables['label']['#markup'] ?? $variables['label']['#markup'] ?? t('events');
+

That's not how the null coalescing operator is used.

immaculatexavier’s picture

Status: Needs work » Needs review
StatusFileSize
new736 bytes
new585 bytes

Attached patch against #6 and #7

avpaderno’s picture

Status: Needs review » Reviewed & tested by the community

Eventually, the code could directly set '@label' without using a intermediate variable, if the resulting line doesn't exceed the 80-character limit, but I will let the project maintainers decide about that.

tbsiqueira’s picture

Thank you all for your work!

I created a PR for this change, and also made a slight change on the proposed solution, I removed the t() function from the "else" because the text is already encapsulated on a t() function

https://github.com/goalgorilla/open_social/pull/3155

tbsiqueira’s picture

Status: Reviewed & tested by the community » Fixed

Issue is fixed and will be available on the next 11.4.x and above versions

  • 5d3163a committed on 11.5.x
    Issue #3314911 by immaculatexavier, pflora, apaderno, dco, tbsiqueira:...

  • 74d1e44 committed on 11.4.x
    Issue #3314911 by immaculatexavier, pflora, apaderno, dco, tbsiqueira:...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.