Problem with settings for multiple rendered item fields

Created on 31 July 2023, over 1 year ago
Updated 7 October 2023, about 1 year ago

Problem/Motivation

I have 3 Rendered Item fields in the Index and all of them have different view modes in configs. But when I call extractItemValues() for my custom highlight functionality it returns one view mode (from the first found field) for all fields.

Proposed resolution

Use Field Identifier to get configs for correct field. Problem that we break after first field in the foreach:

            if ($property instanceof ConfigurablePropertyInterface) {
              $field_info['configuration'] = $property->defaultConfiguration();
              // If the index contains a field with that property, just use the
              // configuration from there instead of the default configuration.
              // This will probably be what users expect in most situations.
              foreach ($this->filterForPropertyPath($index->getFields(), $datasource_id, $property_path) as $field) {
                $field_info['configuration'] = $field->getConfiguration();
                break;
              }
            }
🐛 Bug report
Status

Needs work

Version

1.0

Component

Framework

Created by

🇺🇦Ukraine alexshipilov

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

Comments & Activities

  • Issue created by @alexshipilov
  • 🇺🇦Ukraine alexshipilov

    Patch with fix.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.2 & MySQL 8
    last update over 1 year ago
    540 pass, 2 fail
  • Status changed to Needs work about 1 year ago
  • 🇦🇹Austria drunken monkey Vienna, Austria

    Thanks for reporting this issue!
    The problem here is that the property’s combined ID and the field’s identifier are, in principle, completely different things. It might often be the case that they match, but it’s not necessary, and sometimes not even possible (e.g., for datasource-specific properties). Therefore, your proposed solution is definitely too simple, since it would break the current correct behavior for lots of sites.
    I also don’t quite see how it would even solve your use case: since the $combined_id of all three fields is the same, this would still return the same config for all three fields, just (potentially) a different one than before. I fear that, due to architectural restrictions, the actual information needed to pick the correct field config is unavailable at this place in the code.

    For a custom highlight processor, you might be able to make this work, however, by temporarily (just in code, without saving) removing the other two fields from the index when retrieving the value of the third one. That way, the correct field’s config will always be picked.
    Not very pretty, I admit, but the best I can come up with. Other suggestions very welcome, though.

Production build 0.71.5 2024