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
Comment #2
guignonvThe patch logic sounds good. I'll test and include it in next beta (hopefully this week... things are always delayed... :( ).
Comment #3
guignonvComment #4
guignonvMerged. Thank you for the report and the fix. :)
Comment #6
guignonvApplied by commit #c016c35143ed4b02bd2ca5bdc46f8fee843ff672 and credited.
Comment #7
guignonvIn fact, I read a bit too fast. The fix does not change anything and the tests are passing.
Comment #8
guignonvI 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):
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?
Comment #9
sylvainm commentedThanks 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
Comment #10
sylvainm commentedHere 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
a.json
b.json
and on /test, the 2 entities display only one title, but on /test/b, 2 titles are displaid
Comment #11
sylvainm commentedIn 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
Comment #12
guignonvOK, 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:
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.
Comment #14
guignonvI committed a fix to support field cardinality. Please confirm the fix works as expected and mark the issue reviewed if so.
Comment #15
sylvainm commentedIndeed, my analysis was wrong, and this is fixed with the latest 3.0.x-dev, thank you very much!
Comment #16
guignonvYou're welcome! Thanks for confirming the fix. ;)
Comment #18
guignonv