- Issue created by @pmate
- 🇩🇪Germany mvogel
I got the same problem.
https://git.drupalcode.org/project/views_autocomplete_filters/-/commit/b... introduced the "bug"
with
$entity->$field_name->value
$langcode = \Drupal::languageManager()->getCurrentLanguage()->getId(); $entity = $view->result[$index]->_entity->getTranslation($langcode); $raw_field = $entity->$field_name->value;
The patch does not fix it for us, because in our case we have a user view and join with a node table and the autocomplete exposed form filters some field value of the node table, and the user entity can not have the node field in this case.
Proposed solution:
The code has to check to which entity the field in the exposed form belongs to get the right field with the translation. @mvogel I was suspecting the patch will work only for my case.
Could you give attached patch a try?
- 🇩🇪Germany mvogel
Thanks for your patch. I tested the patch but it does not work.
It will only work when the field belongs to the entity type.In my case, I got a user view, so the
$entity
will be a user object. My user object has an entity reference field to a node object. In my view, I can filter for a field in the node object (like for example field_node_title). The code will then try$entity->field_node_title->value
which will always be null, because the user object hasn't a field node_title Thanks, it makes sense.
So my case is different from yours and I guess that the real solution would be to revert the https://git.drupalcode.org/project/views_autocomplete_filters/-/commit/b... and look for a different solution for translations but I'm not sure.
- 🇦🇹Austria maxilein
1.4 killed it for me using the autocomplete on the name (not ID) of a term reference field in the filter.
My case, which I think is not rare, because you do not select manually be entering a term ID:
The term name (for the autocomplete) is not part of the filtered entity. The entity only has the term reference field. But I filter on the term name which has to be pulled in via a relationship.entity with term reference field -> relationship to taxonomy -> retrieve the term name for the autocomplete.
- 🇺🇸United States crutch
Getting same error. I tried the diff and it isn't honoring the entity reference relationship using title.
- First commit to issue fork.
- @kostask opened merge request.
- 🇬🇷Greece kostask
The above MR partially reverts https://git.drupalcode.org/project/views_autocomplete_filters/-/commit/b.... Not a fix as "Autocomplete is not working for languages other than the default language" is reverted, but I added as a hotfix for anyone experiencing this issue and not having translations.
- 🇧🇬Bulgaria joro78
I still have problems with the views autocomplete filters. I think that the field type, we are requesting as an exposed filter, causes the issue. Autocomplete filters work when Title field is exposed on a multilingual site. However when using it to get values from an address field, such as locality for instance, the error above appears in the log and data is not visualized into the autocomplete field.
- 🇨🇦Canada joseph.olstad
going with the MR for now, using patch
https://git.drupalcode.org/project/views_autocomplete_filters/-/merge_re...
- Status changed to Needs review
about 1 year ago 7:42am 14 September 2023 - Status changed to RTBC
about 1 year ago 1:03pm 14 September 2023 - 🇨🇦Canada joseph.olstad
The MR resolves repeated PHP errors, we had so many that it was contributing to a server crash.
- Status changed to Needs work
about 1 year ago 1:56pm 14 September 2023 - 🇨🇦Canada joseph.olstad
Ok, so reverting this causes another regression.
Ok so a possible hint here, our default language is NOT English and we do have a second language.
- Status changed to Needs review
about 1 year ago 5:47pm 14 September 2023 - 🇷🇴Romania vasike Ramnicu Valcea
Unfortunately, the previous attempts were more about revert the introducing change, if i didn't miss something.
So for start i merged a commit about translation (missing) https://www.drupal.org/project/views_autocomplete_filters/issues/3353406... 🐛 Check entity field really is translatable Needs review
To be sure we are getting the value, even there is no translation.
So, also please check this issue, maybe we could also close this one, too.This issue looks quite simple, we're trying to get a value from entity - RAW value, but for "another" field name.
Which is usual in Views, to get with some views, that havefield_something_2
as "identifier".So, i pushed a commit, that get the real field name. before trying to use the entity field data.
I hope it's the solution, but for now, i'll put (only) on "Needs Review".thanks all for your efforts - attempts and testing.
p.s. if someone thinks, credit is needed for the efforts on solution, please, comment about it. thanks
- 🇩🇪Germany mvogel
Unfortunately, your commit does not fix my problem. For example, I got a "user entity" view that has an entity reference field to a node entity. In my exposed form I can filter this entity reference field. So I got the problem:
$entity
is an instance of User and the$real_field_name
is a field from a NodeType, that results inAttempt to read property "value" on null in Drupal\views_autocomplete_filters\Controller\ViewsAutocompleteFiltersController->autocomplete() Line 231
Steps to reproduce:
- Create an entity reference field for user that points for example on node article
- create a view for users that has an exposed filter for the entity reference field from 1 for example the title field (activate views autocomplete filters)
- Type something in the input field and get the error message from above
- 🇷🇴Romania vasike Ramnicu Valcea
@mvogel thanks for the feedback, could this be related with
https://www.drupal.org/project/views_autocomplete_filters/issues/3348802 🐛 Autocomplete with entity reference/relationship Needs review ?i know it worked ... years ago
- 🇩🇪Germany mvogel
You are right, my problem is the issue you posted. I tested your commit and it fixes the problem with different field identifiers
field_somethink_2
sorry for the unnecessary noise.
- 🇷🇴Romania vasike Ramnicu Valcea
@mvogel it's not noise, it's voice ... and it's important for issues and solutions.
thanks a lot - 🇷🇴Romania vasike Ramnicu Valcea
@mvogel could you, please, check again you issue.
A feedback is welcomed also on the related issue https://www.drupal.org/project/views_autocomplete_filters/issues/3348802... 🐛 Autocomplete with entity reference/relationship Needs review
thanks a lot
- 🇷🇴Romania vasike Ramnicu Valcea
it seems there was similar issue for Combine filters and maybe other cases.
There could filters for "non fields of an entity".So i pushed a commit with extra checks and fallback for no entity for the given filter.
i hope we're close to a solution here. please test and feedback
thanks - 🇷🇴Romania vasike Ramnicu Valcea
thanks to @mvogel feedback
on related issue https://www.drupal.org/project/views_autocomplete_filters/issues/3348802... 🐛 Autocomplete with entity reference/relationship Needs review
i pushed another fix, about field name value.
And it was the same error on some cases.let's see the verdicts.
- Status changed to Fixed
about 1 year ago 9:20am 9 October 2023 - 🇷🇴Romania vasike Ramnicu Valcea
i think we can close this.
please, feel free to re-open, if not done.
Automatically closed - issue fixed for 2 weeks with no activity.