PHP 8.1 settings form error

Created on 22 June 2023, over 1 year ago
Updated 11 September 2023, about 1 year ago

Problem/Motivation

Using php 8.1 the settings form at /admin/config/system/hidden_language is inaccessible if the form values are empty.
Drupal: 9.5.9
PHP: 8.1.19

The website encountered an unexpected error. Please try again later.
TypeError: implode(): Argument #1 ($pieces) must be of type array, string given in implode() (line 66 of modules/contrib/hidden_language/src/Form/HiddenLanguageForm.php).

Steps to reproduce

After installing go to /admin/config/system/hidden_language .

Proposed resolution

In HiddenLanguageManager in functions getRoutesException() and getRoutesException() check if the returned setting is null and return an empty array instead of calling json_decode().

--- a/web/modules/contrib/hidden_language/src/HiddenLanguageManager.php
+++ b/web/modules/contrib/hidden_language/src/HiddenLanguageManager.php
@@ -56,7 +56,7 @@ public function __construct(ConfigFactory $config_factory, PathValidator $path_v
    *   Array of configurated routes.
    */
   public function getRoutesException() {
-    return json_decode($this->hiddenLanguageSettings->get('route_name'));
+    return $this->hiddenLanguageSettings->get('route_name') ? json_decode($this->hiddenLanguageSettings->get('route_name')) : [];
   }
 
   /**
@@ -66,7 +66,7 @@ public function getRoutesException() {
    *   Array of configurated paths.
    */
   public function getPathsException() {
-    return json_decode($this->hiddenLanguageSettings->get('path'));
+    return $this->hiddenLanguageSettings->get('path') ? json_decode($this->hiddenLanguageSettings->get('path')) : [];
   }

๐Ÿ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

๐Ÿ‡ญ๐Ÿ‡บHungary Zsuffa Dรกvid

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024