We need a Commerce-specific fix for this core issue #2337517: EntityViewsData does not handle main properties correctly.
Quoting myself from that issue:
The resulting views data is broken for:
1) Fields with no main property name
2) Fields with multiple properties whose main property is not the first oneWhat happens in case of #1 is that the first random property gets promoted to main, so it can't be used separately anymore.
For address fields this is the "langcode" field. For price fields this is the "number" field.
Instead, when the main property name is NULL, we should be adding a pseudo-field whose only purpose is to render the field.
That will keep access to the individual properties intact.The other related problem is that mapSingleFieldViewsData() uses the "field" handler for every property, which results in the entire field being rendered, instead of just the individual property. We should be using the "standard" handler for non-main properties.
#5 we realized that we can't introduce the pseudo-field because the behavior change would represent too big of a backwards compatibility break. However, we can do the following:
1) Use the field's main property name, instead of always falling back to the first property. This fixes tax number fields, where the main property is value but the first property is type.
2) Fix views data to only use the "field" handler for the main property, not for all of them. This allows people to output just the currency code, for example.
And since we are already messing with the logic, we can make sure that each handler has a field_name defined, removing the workaround from processViewsDataForDatetime and others.
Comment | File | Size | Author |
---|---|---|---|
#6 | 3097581-6-fix-multivalue-fields.patch | 4.23 KB | bojanz |
| |||
#5 | 3097581-5-fix-multivalue-fields.patch | 4.85 KB | bojanz |
#4 | 3097581-4-fix-multivalue-fields.patch | 3.06 KB | bojanz |
#3 | 3097581-3-fix-multivalue-fields.patch | 2.45 KB | bojanz |
Comments
Comment #2
bojanz CreditAttribution: bojanz at Centarro commentedComment #3
bojanz CreditAttribution: bojanz at Centarro commentedInitial patch.
Comment #4
bojanz CreditAttribution: bojanz at Centarro commentedThis one should be less broken.
Comment #5
bojanz CreditAttribution: bojanz at Centarro commentedThis is the final patch.
However, the fix is too aggressive.
While it makes the integration more logical, it causes all existing views to show unformatted prices ($20 becomes 20.000000) since the old views data entry now points to the actual column. It's even worse for anyone who had a rendered address, that just shows the langcode now.
So we need to leave this fix for another day, and reduce its scope a bit.
Comment #6
bojanz CreditAttribution: bojanz at Centarro commentedUpdating title and issue summary.
Attaching new, less ambitious, patch.
Comment #7
bojanz CreditAttribution: bojanz at Centarro commentedI accidentally a word.
Comment #9
bojanz CreditAttribution: bojanz at Centarro commentedCommitted.