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.

CommentFileSizeAuthor
#5 success-screen.png94.41 KBraveen_thakur51
#5 error.png42.31 KBraveen_thakur51
Command icon 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

omkar_yewale created an issue. See original summary.

omkar_yewale’s picture

Assigned: omkar_yewale » Unassigned
Status: Needs work » Needs review

The issue has been handled with solution 1, and MR has been created. Please review it.

shani maurya’s picture

Assigned: Unassigned » shani maurya
raveen_thakur51’s picture

StatusFileSize
new42.31 KB
new94.41 KB

Hello 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.

zealialize’s picture

Status: Needs review » Closed (fixed)

Thanks for reporting the problem.
I had this problem too, so I fixed it and released version 2.0.2.

omkar_yewale’s picture

Hi @zealialize, Not sure why the credits were not given to anyone.

raveen_thakur51’s picture

++

zealialize’s picture

I didn't know about credit.
Marked on those who you think have contributed.
Thank you for pointing this out.