Error: Call to a member function getKeyValue() on null and Deprecated function: strlen(): Passing null to parameter #1 ($string)

Created on 6 September 2023, 10 months ago
Updated 27 June 2024, about 20 hours ago

Problem/Motivation

I am getting this couple issues after installing key module and most likely both are related to php 8.1 upgrade.
1. [error] Error: Call to a member function getKeyValue() on null in Drupal\key\KeyConfigOverrides->loadOverrides() (line 89 of /app/docroot/modules/contrib/key/src/KeyConfigOverrides.php)

2. Deprecated function: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\key\Plugin\KeyProviderBase::obscureValue() (line 66 of modules/contrib/key/src/Plugin/KeyProviderBase.php).

Steps to reproduce

1. Install key module in a project and add your necessary key overrides.
2. During the project build the 1st issue occurs.
3. Once you bypass the 1st issue and from UI go to the keys /admin/config/system/keys and click on managing one of the keys, the 2nd issue pops up as a deprecated function error.

Proposed resolution

For the first issue, in KeyConfigOverrides.php change this to check the null value first -
Before
$key_value = $storage->load($key_id)->getKeyValue();
After
$key_value = $storage->load($key_id) ? $storage->load($key_id)->getKeyValue() : '';

For the 2nd issue, in KeyProviderBase.php change this -
Before
elseif (strlen($key_value) - $options['visible_right'] > 0) {
After
elseif (!is_null($key_value) && strlen($key_value) - $options['visible_right'] > 0) {

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡¦πŸ‡ΊAustralia Nadim Hossain

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

Comments & Activities

Production build 0.69.0 2024