Problem/Motivation

When using Multiple mapping with "stop at first non-empty mapping" option used, it does not work and the multiple values are used instead of the first one.

When mapping multiple raw values to a field with a limited cardinality, mapped values may exceed the maximum number of allowed elements.

Steps to reproduce

- Create a field with a cardinality of 2
- Map it to a raw value that provides more than 2 elements.
All the elements are mapped.

Proposed resolution

Take into account field cardinality configuration when mapping values and truncate too large arrays as needed.

Comments

sylvainm created an issue. See original summary.

guignonv’s picture

The patch logic sounds good. I'll test and include it in next beta (hopefully this week... things are always delayed... :( ).

guignonv’s picture

Status: Active » Needs review
guignonv’s picture

Status: Needs review » Fixed

Merged. Thank you for the report and the fix. :)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

guignonv’s picture

Applied by commit #c016c35143ed4b02bd2ca5bdc46f8fee843ff672 and credited.

guignonv’s picture

Status: Fixed » Needs work

In fact, I read a bit too fast. The fix does not change anything and the tests are passing.

guignonv’s picture

Status: Needs work » Postponed (maintainer needs more info)

I took time to investigate. First, the patch you propose does nothing. It sets a value that is not used anywhere. That's why automated tests were still passing and I though the fix was working.

After reviewing the fix again, I saw it was useless so I manually tested this dataset to make sure everything works fine (json dataset):

{
"a":{
  "id": "a",
  "title": "element 1",
  "field1": "toto",
  "field2": "titi",
  "field3": "tutu"
},
"b":{
  "id": "b",
  "title": "element 2",
  "field1": "",
  "field2": "titi",
  "field3": "tutu"
},
"c":{
  "id": "c",
  "title": "element 3",
  "field1": 0,
  "field2": "titi",
  "field3": "tutu"
},
"d":{
  "id": "d",
  "title": "element 4",
  "field1": null,
  "field2": "titi",
  "field3": "tutu"
},
"e":{
  "id": "e",
  "title": "element 5",
  "field2": "titi",
  "field3": "tutu"
},
"f":{
  "id": "f",
  "title": "element 6",
  "field1": null,
  "field3": "tutu"
},
"g":{
  "id": "g",
  "title": "element 7",
  "field1": [],
  "field2": null,
  "field3": "tutu"
},
"h":{
  "id": "h",
  "title": "element 8",
  "field1": ["a", "b", "c"],
  "field2": null,
  "field3": "tutu"
},
"i":{
  "id": "i",
  "title": "element 9",
  "field1": [""],
  "field2": ["", "", "x"],
  "field3": "tutu"
},
"j":{
  "id": "j",
  "title": "element 10",
  "field1": [" "],
  "field2": ["", null, "x"],
  "field3": "tutu"
}
}

I used a test external entity type with a field "multitext" that was mapped using multiple mapping: first field was set to "field1", second to "field2" and third to "field3". All those 3 mappings were using the "simple" mapping type with no data processors. The loading order was set to "1,2,3" with "stop at first non-empty mapping".

Results are the expected ones for "multitext":
element1: "toto"
element2: "titi"
element3: 0
element4: "titi"
element5: "titi"
element6: "tutu"
element7: "tutu"
element8: ["a", "b", "c"]
element9: "x"
element10: " "

For me, all is working as designed. I cannot reproduce your issue. Could you elaborate more on your settings and provide your exact mapping for a given dataset, just like I did?

sylvainm’s picture

Assigned: Unassigned » sylvainm

Thanks for your time and tests, i'll do more tests and give you what is needed asap.

One thing was not precise in my description: my destination field is the title (label), which is single valued, i guess

sylvainm’s picture

Assigned: sylvainm » Unassigned
Status: Postponed (maintainer needs more info) » Active
StatusFileSize
new3.16 KB

Here are more informations to reproduce the problem i encounter: the problem apperas only on the view_mode of the entity, not on the list, which uses the label method on the entity.

You can reproduce with the attached test external entity_type and the data which follows:

data.json

{
  "list": [
    {
      "id": "a"
    },
    {
      "id": "b"
    }
  ],
  "count": 2
}

a.json

{
  "id": "a",
  "title": {"title":  "element 1"}
}

b.json

{
  "id": "b",
  "title": [
    {
      "rn": "1",
      "title":  "element 2 - title 1"
    },
    {
      "rn": "2",
      "title":  "element 2 - title 2"
    }
  ]
}

and on /test, the 2 entities display only one title, but on /test/b, 2 titles are displaid

sylvainm’s picture

In the patch, the value which is set is the value which is returned by the function (extractPropertyValuesFromRawData)

Let me know if you need more informations to reproduce

guignonv’s picture

Title: Multiple mapping: stop at first non-empty mapping » Field cardinality is not taken into account on field mapping
Assigned: Unassigned » guignonv
Issue summary: View changes

OK, everything work as designed, it is just a different problem of mapping than the one you describe. I agree things are not easy to understand, and the documentation and setting descriptions could be better.

With your example on the "b" entity, the multiple mapping first tries to get "title.title" which does not exist. Then it tries to get "title.*.title" which is a non-null array of values. It will be assigned to the title field. So it works as expected. To convince you, here is another example:

{
  "id": "c",
  "title": {
    "title": "element 3 - title 1",
    "0": {
      "title":  "element 3 - title 2"
    },
    "1": {
      "title":  "element 3 - title 3"
    }
  }
}

Try it and you will see only "element 3 - title 1" will be used as title.

The problem you meet is not related to the multiple mapping. It is how external entity provides data to Drupal fields: it currently does not take into account the field cardinality (while it should). The "title" field is supposed to only have one value but with your dataset, it is filled with a set of values. I should take into account the field cardinality configuration to truncate array of values.

So I'll update the issue description. Meanwhile, if it works for you, you may use a different second mapping: "title.0.title", which should only keep the first title value. Hopefully, you don't have in your dataset a first "null" title when there is a list of titles...
There may be other ways to solve you current problem, maybe using conditional mapping but I don't have time to investigate more that, and anyway, the real problem behind is different and solving it will solve your problem as well.

  • guignonv committed d3ac2001 on 3.0.x
    Fixes field cardinality support (issue #3562888)
    
guignonv’s picture

Status: Active » Needs review

I committed a fix to support field cardinality. Please confirm the fix works as expected and mark the issue reviewed if so.

sylvainm’s picture

Status: Needs review » Reviewed & tested by the community

Indeed, my analysis was wrong, and this is fixed with the latest 3.0.x-dev, thank you very much!

guignonv’s picture

Status: Reviewed & tested by the community » Fixed

You're welcome! Thanks for confirming the fix. ;)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

guignonv’s picture

Assigned: guignonv » Unassigned

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.