Allow other modules to alter the autocomplete values

Created on 12 October 2023, almost 2 years ago
Updated 13 August 2024, about 1 year ago

Problem/Motivation

Hi,
we are using the contrib module real name for the user display name. If you use the real name "field" as a filter, the real name value is a string attached to the user object.

$raw_field = $entity->$real_field_name->value;

$raw_field = $entity->realname->value;

The $entity->realname is a type of string, and we got the error message Warning: Attempt to read property "value" on string.

Steps to reproduce

  1. Install the real name module and config the real name value setting
  2. Add as a filter to a user view and expose it with views autocomplete filter
  3. Search for a real name value and get the error message above. No autocomplete dropdown will be rendered

Proposed resolution

It is a really specific problem with the contrib real name module. So I don't know if you want to change it at all. But I added a "if type check" from

$raw_field = $entity->$real_field_name->value;

to

            $real_field = $entity->$real_field_name;
            if ($real_field instanceof FieldItemListInterface) {
              $raw_field = $real_field->value;
            }
            elseif (is_string($real_field)) {
              $raw_field = $real_field;
            }

and it works for my use cases. I am unsure if FieldItemListInterface is sufficient for all fields in exposed forms.

Feature request
Status

Needs work

Version

2.0

Component

Code

Created by

🇩🇪Germany mvogel

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