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 one

What 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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz created an issue. See original summary.

bojanz’s picture

bojanz’s picture

Status: Active » Needs review
FileSize
2.45 KB

Initial patch.

bojanz’s picture

bojanz’s picture

This 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.

bojanz’s picture

Title: EntityViewsData generates incorrect data for fields with no main property (address, price) » EntityViewsData generates incorrect data for fields with multiple (address, price)
Issue summary: View changes
FileSize
4.23 KB

Updating title and issue summary.

Attaching new, less ambitious, patch.

bojanz’s picture

Title: EntityViewsData generates incorrect data for fields with multiple (address, price) » EntityViewsData generates incorrect data for fields with multiple properties (address, price)

I accidentally a word.

  • bojanz committed 2c64af7 on 8.x-2.x
    Issue #3097581 by bojanz: EntityViewsData generates incorrect data for...
bojanz’s picture

Status: Needs review » Fixed

Committed.

Status: Fixed » Closed (fixed)

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