Reference multivalue base fields are missing the "delta" views field

Created on 4 January 2024, 12 months ago
Updated 7 May 2024, 8 months ago

Problem/Motivation

This was discovered in 💬 Sort Reference view by last name of first Contributor Active .
Core doesn't generate the "delta" field for base fields, so we'll have to do it in ReferenceViewsData.
Matching core issue: #3097568: EntityViewsData does not generate a "additional fields" nor "delta" field for multivalue base fields

Steps to reproduce

  1. Create a view to display References.
  2. Try adding a filter, for example for the author field delta. (This one will not be found.)

Proposed resolution

Seeing that the Commerce Core and Entity API modules have already presented this problem, I suggest following your correction approach.
Commerce Core: #3097586: Multivalue base fields are missing the "delta" views field
Entity API: #3116128: Add an EntityViewsData handler for improved Views integration

Add the delta if it is a multiple field in ReferenceViewsData.

  protected function mapFieldDefinition($table, $field_name, FieldDefinitionInterface $field_definition, TableMappingInterface $table_mapping, &$table_data) {
    parent::mapFieldDefinition($table, $field_name, $field_definition, $table_mapping, $table_data);

    if ($this->getFieldStorageDefinitions()[$field_name]->isMultiple()) {
      $label = $field_definition->getLabel();

      $table_data['delta'] = [
        'title' => $this->t('@label (@name:delta)', ['@label' => $label, '@name' => $field_name]),
        'title short' => t('@label:delta', ['@label' => $label]),
      ];
      ...
  }

Remaining tasks

Review of the proposed solution.

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇵🇹Portugal lolgm

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024