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
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3385523-4.patch | 1.26 KB | nadim hossain |
Issue fork key-3385523
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
Comment #3
nadim hossain commentedCreated a merge request and also added this patch version to use it in the composer to avoid using the merge request diff directly.
Comment #4
nadim hossain commentedThanks for the review @matthew. I have update the merge request and adding a updated patch as well.
Comment #5
neclimdulThis triggers two loads. It should be either something like:
Or if we can require PHP 8 the much easier to read:
The interface says this should only be a string. What's causing it to be null? Do you have a deeper trace so we can maybe fix the code that's not following the interface?
Comment #6
rolodmonkey commentedThis looks like a duplicate? #3323238: Deprecated Function: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\key\Plugin\KeyType\EncryptionKeyType->validateKeyValue() (line 124 of modules/contrib/key/src/Plugin/KeyType/EncryptionKeyType.php)
Comment #7
monaw commentedi noticed this patch is still not in the latest release which is June 2024 and wondering why not? is there a problem?
Comment #8
rlhawkYes, this is a partial duplicate of #3323238: Deprecated Function: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in Drupal\key\Plugin\KeyType\EncryptionKeyType->validateKeyValue() (line 124 of modules/contrib/key/src/Plugin/KeyType/EncryptionKeyType.php). Let's focus this issue on the
Error: Call to a member function getKeyValue() on nullpart of it.Comment #10
rajeshreeputraComment #13
japerry