Missing google_translator_disclaimer_title setting causes PHP 8.1 errors

Created on 15 September 2023, 10 months ago
Updated 5 March 2024, 4 months ago

Problem/Motivation

After upgrading version 1 to version 2, for Drupal 10 support I see the following errors on all pages:

Deprecated function: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in Drupal\Component\Utility\Xss::filter() (line 69 of core/lib/Drupal/Component/Utility/Xss.php).
Drupal\Component\Utility\Xss::filter(NULL, Array) (Line: 123)
Drupal\Component\Utility\Xss::filterAdmin(NULL) (Line: 181)
Drupal\google_translator\Plugin\Block\GoogleTranslator->attachDisclaimer(Array) (Line: 146)
Drupal\google_translator\Plugin\Block\GoogleTranslator->build() (Line: 138)
Deprecated function: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\Component\Utility\Unicode::validateUtf8() (line 395 of core/lib/Drupal/Component/Utility/Unicode.php).
Drupal\Component\Utility\Unicode::validateUtf8(NULL) (Line: 65)
Drupal\Component\Utility\Xss::filter(NULL, Array) (Line: 123)
Drupal\Component\Utility\Xss::filterAdmin(NULL) (Line: 181)
Drupal\google_translator\Plugin\Block\GoogleTranslator->attachDisclaimer(Array) (Line: 146)
Drupal\google_translator\Plugin\Block\GoogleTranslator->build() (Line: 138)

Steps to reproduce

  1. Install google_translator version 1 on Drupal 9 with php 8.1
  2. Enable the block into a theme header region.
  3. Update google_translator to version 2 in composer.
  4. Load any page where the translator block should be visible.

Fundamentally, the problem is that a new setting google_translator_disclaimer_title was introduced in version 2, but there wasn't anything done to set a default value when upgrading, so the call to
Xss::filterAdmin($this->moduleConfig->get('google_translator_disclaimer_title')) passes a NULL value, which triggers this PHP error in PHP 8.1

Proposed resolution

Add a new hook_update_N function to set the default value of the google_translator_disclaimer_title in into the active configuration of this module settings.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ͺπŸ‡¨Ecuador jwilson3

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

Merge Requests

Comments & Activities

Production build 0.69.0 2024