Having allowed_values causes error on installation

Created on 24 April 2024, 9 months ago
Updated 16 May 2024, 9 months ago

Problem/Motivation

Running drush si -y --existing-config when config contains a datafield with allowed values throws an error:

[error] TypeError: trim(): Argument #1 ($string) must be of type string, array given in trim() (line 634 of /var/www/drupal/web/modules/contrib/datafield/src/Plugin/Field/FieldType/DataField.php) #0 /var/www/drupal/web/modules/contrib/datafield/src/Plugin/Field/FieldType/DataField.php(634): trim(Array)

Steps to reproduce

  1. Create a datafield with a text subfield.
  2. In the settings for the subfield, add allowed values
  3. Export config (drush cex -y)
  4. Try to create a fresh installation from the config (drush si -y --existing-config)
  5. See error

Proposed resolution

Looks like allowed values are saved as an array when values exist, or as an empty string when they do not. Here is an example from file field.field.config_pages.school_settings.field_calendars.yml:

settings:
  field_settings:
    type:
      label: Type
      list: true
      allowed_values:
        -
          label: Google
          value: google
        -
          label: 'Outlook 365'
          value: outlook_365
      required: true
    account:
      label: Account
      list: false
      allowed_values: ''
      required: true

So, it looks like we need to either:

  1. Refactor DataField.php:634 to better account for arrays
  2. Change how field settings are stored

Remaining tasks

User interface changes

None

API changes

None

Data model changes

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bander2

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

Comments & Activities

Production build 0.71.5 2024