TypeError: Drupal\field_redirect\Service\UtilityService::toArray(): Argument #1 ($mappings_string) must be of type string, null given.

Created on 12 May 2023, over 1 year ago
Updated 23 May 2023, over 1 year ago

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.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇮🇳India omkar_yewale Mumbai

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

Comments & Activities

Production build 0.71.5 2024