Problem/Motivation
I'm getting the following error with Drupal 10 and PHP 8.
TypeError: Drupal\field_redirect\Service\UtilityService::toArray(): Argument #1 ($mappings_string) must be of type string, null given.
Steps to reproduce
- Install module
- Navigate to the module configuration page. (/admin/config/search/field-redirect)
- Try to save the form without any data
- you will get TypeError: Drupal\field_redirect\Service\UtilityService::toArray(): Argument #1 ($mappings_string) must be of type string, null given.
Proposed resolution
Causing this issue because of passing a null value.
solution 1:
$this->settings
->set(UtilityService::MODULE_NAME . '.mappings', $this->utility->toArray($form_state->getValue('mappings', '')))
->save();
To
$mappings = $form_state->getValue('mappings') ?? '';
$this->settings
->set(UtilityService::MODULE_NAME . '.mappings', $this->utility->toArray($mappings))
->save();
Solution 2:
Add the required option to "The redirect mapping settings of entity (type and bundle) and fields" field.
Comments
Comment #3
omkar_yewale commentedThe issue has been handled with solution 1, and MR has been created. Please review it.
Comment #4
shani mauryaComment #5
raveen_thakur51 commentedHello Folks!
I have implemented the solution 1 and it worked perfectly fine for me. I am using Drupal version - 9.5 & PHP version - 8.1
I am adding screenshots for reference. Please review.
And Thank You.
Comment #6
zealializeThanks for reporting the problem.
I had this problem too, so I fixed it and released version 2.0.2.
Comment #7
omkar_yewale commentedHi @zealialize, Not sure why the credits were not given to anyone.
Comment #8
raveen_thakur51 commented++
Comment #9
zealializeI didn't know about credit.
Marked on those who you think have contributed.
Thank you for pointing this out.