Problem/Motivation

The module doesn't work with entity reference field on commerce entities.

Steps to reproduce

Add a entity reference field, for example a taxonomy term reference on a Commerce Product type.
Create a view of commerce products.
Try to add a entityreference filter on that field.

Proposed resolution

The reason is that inside entityreference_filter_views_data_alter
the check for commerce entities is nested:

      elseif (mb_strpos($table_name, 'commerce_product') !== FALSE) {
        // Commerce product variations.
        if ($field_name === 'variation_id' || (mb_substr($field_name, -10) === '_target_id' && $field_info['filter']['field_name'] === 'variations')) {
          $target_entity_type = 'commerce_product_variation';
        }
        // Commerce product.
        if ($field_name === 'product_id') {
          $target_entity_type = 'commerce_product';
        }
      }

Therefore, for entity reference field for those entities, the outer condition is met, while the inner not.
The following which consider all other entityreference fields is then skipped.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

giuseppe87 created an issue. See original summary.

giuseppe87’s picture

Status: Active » Needs review
maximkashuba’s picture

Status: Needs review » Fixed

Thanks for the report and the MR, @giuseppe87.

You diagnosed it correctly: in the old entityreference_filter.views.inc the commerce branch was part of an if/elseif chain, so for a table matching "commerce_product" whose column was neither variation_id nor product_id the "other entityreference fields" branch was never reached.

That whole hardcoded chain (nid/uid/tid/gid + commerce) is gone as of 2.0.0-beta6. The hook now uses the Entity API (EntityTypeManager::getDefinitions()) to map every content entity type's base/data table and ID key, and entity reference fields are resolved from the field storage config's target_type — there is no commerce-specific branch left to short-circuit.

Verified on Drupal 10.3 with commerce 3.x: an entity reference field added to a commerce product now gets the filter handler.

Marking as fixed in 2.0.0-beta6.
Closing MR !26 as no longer applicable — please reopen if you still hit this on 2.0.x-dev.

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.