Custom entities BaseFields with cardinality are taking wrong column name

Created on 15 June 2023, about 1 year ago

Problem/Motivation

When a user adds a VERF filter for a custom entity base fields with cardinality (multiple values), the filter is not assigning the correct column name (field_target_id). It is taking something like "field_field" as column name.

Steps to reproduce

1. Create a custom entity with a "entity_reference" base field and cardinality ulimited:

<?php 
[...]
$fields['my_field'] = BaseFieldDefinition::create('entity_reference')
      ->setSetting('target_type', 'target_entity_id')
      ->setSetting('handler', 'default')
      ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED); 
[...]
?>

2. Create a view for the created entity and add a VERF filter for the field "my_field"

Proposed resolution

The solution should be taking the column name from the schema when creating the filter definition:

<?php
[...]
 $columns = $base_field_storage_definition->getColumns();
 $column_name = isset($columns) ? array_key_first($columns) : $field_name;
 $column_name = $table_mapping->getFieldColumnName($base_field_storage_definition, $column_name);
[...]
?>
πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain mrjey Sevilla

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024