List field values have labels as keys

Created on 27 September 2022, about 2 years ago
Updated 17 February 2023, over 1 year ago

Problem/Motivation

When a list field has keys that differ from its labels, the remote entity is shown with its label as the key and therefore won't import.

Steps to reproduce

Set up an entity with a list field whose allowed values are, for example,

age5-12|Ages 5-12
age13-17|Ages 13-17

Create content with a value in that field. Better yet if you can have the same entity on both sites.
Set up a channel and all that to share the data between sites. Enable Entity Share Diff module on the client site so you can see what's going on. Look at the diff of an entity. The local entity's value is shown as - 'Ages 13-17 (age13-17)' (which is correct), but the remote entity's value is shown as - ' (Ages 13-17)' (which is incorrect).
Viewing the diff gives you a warning like

Warning: Undefined array key "Ages 13-17" in Drupal\entity_share_diff\Plugin\DiffGenerator\ListFieldDiffParser->build() (line 38 of /app/web/modules/contrib/entity_share/modules/entity_share_diff/src/Plugin/DiffGenerator/ListFieldDiffParser.php)

and attempting to synchronize it gives an error like

Error: Call to a member function getAlias() on null in Drupal\path\Plugin\Field\FieldType\PathItem->postSave() (line 88 of /app/web/core/modules/path/src/Plugin/Field/FieldType/PathItem.php)

Proposed resolution

I have no idea, sorry.

πŸ› Bug report
Status

Closed: cannot reproduce

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States BenStallings

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·
  • πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

    The import error is related to πŸ’¬ Call to a member function getAlias on null Fixed .

    Here let's focus on the diff problem.

  • Issue was unassigned.
  • Status changed to Closed: cannot reproduce over 1 year ago
  • πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

    Hi,

    I am sorry, but I cannot reproduce the warning in the diff. See the attached screenshots.

    I used the list field used in the tests:
    - https://git.drupalcode.org/project/entity_share/-/blob/8.x-3.x/tests/mod...
    - https://git.drupalcode.org/project/entity_share/-/blob/8.x-3.x/tests/mod...

    I think it matches your requirements.

    After first successful try, I put cardinality to unlimited to check if this could be the source of the problem, but it was also ok.

    If you witness this issue on "real" content, maybe between the moment you imported a content for the first time, and the moment you want to check the diff, you made some changes in the JSON:API output with JSON:API Extras field enhancer or something else and so the output is not the expected one for the diff.

            "field_es_test_list_text": [
              "choice_1",
              "choice_2",
              "choice_3"
            ],
    

    By default it should be the keys that are exposed so if you have the same keys between your website it should be ok.

    When writing the comment, I have an idea, let met check if it is possible to have keys with spaces or special characters, maybe that's the problem source.

  • πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

    I tried with configuration:

    choice_1|Choice 1
    choice_2|Choice 2
    choice_3|Choice 3
    age5-12|Ages 5-12
    age13-17|Ages 13-17
    foo bar|Test

    The JSON:API output:

            "field_es_test_list_text": [
              "choice_1",
              "choice_2",
              "choice_3",
              "age5-12",
              "age13-17",
              "foo bar"
            ],
    

    See the diff output in the attached screenshot.

  • πŸ‡«πŸ‡·France Grimreaper France πŸ‡«πŸ‡·

    Feel free to re-open if able to provide steps to reproduce starting form a fresh Drupal install.

Production build 0.71.5 2024