TypeError: Return value must be of type string

Created on 9 June 2025, about 1 month ago

Problem/Motivation

Here's the log with mobile detect

TypeError: Drupal\mobile_detect\Plugin\Condition\MobileDetectDeviceType::summary(): Return value must be of type string, Drupal\Core\StringTranslation\TranslatableMarkup returned in Drupal\mobile_detect\Plugin\Condition\MobileDetectDeviceType->summary() (line 92 of /home/pearls/public_html/d11site/web/modules/contrib/mobile_detect/src/Plugin/Condition/MobileDetectDeviceType.php).

Steps to reproduce

Proposed resolution

Convert the returned value to a string by wrapping the $this->t() call with (string).

  public function summary(): string {
    $devices = implode(', ', $this->configuration['devices']);
    return $this->isNegated()
      ? $this->t('The device is not @devices', ['@devices' => $devices])
      : $this->t('The device is @devices', ['@devices' => $devices]);
  }

change "return $this->isNegated()" to "return (string) ($this->isNegated()"

💬 Support request
Status

Active

Version

4.0

Component

Code

Created by

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

Comments & Activities

Production build 0.71.5 2024