Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
The entity autocomplete form elemenet displays default values (entity labels) only in the default entity language.
Proposed resolution
Display them in the current content language, using \Drupal\Core\Entity\EntityRepositoryInterface::getTranslationFromContext
.
Remaining tasks
None.
User interface changes
Entity labels will be displayed in the current content language.
API changes
Nope.
Data model changes
Nope.
Comments
Comment #2
Maouna CreditAttribution: Maouna at bio.logis Genetic Information Management GmbH commentedThese are the patches first uploaded at https://www.drupal.org/node/2144377#comment-12004216 and https://www.drupal.org/node/2144377#comment-12002618
Comment #4
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedI reviewed this patch in #2144377: Entity reference autocomplete lists entity labels only in current content language, which is actually about two different bugs.
This patch correctly solves the part where default value entity labels are not displayed in the correct language.
Comment #5
alexpottNice find and the fix does look good. Just a concern about the changes to the test.
A couple of things here. Moving the login changes what is being tested so we're losing anonymous testing of:
But also we're using $this->rootUser which means we're logged in as user 1 which sometimes can do and see things no other user can - which magnifies the danger of this change. A simple solution would be to just not do the first
$this->assertEntityReferenceFields();
and not move the user login since that would make this concern out-of-scope for this issue.Comment #6
Maouna CreditAttribution: Maouna at bio.logis Genetic Information Management GmbH commentedYes, I understand the problem with using user 1 in this test. But I disagree with the proposal of removing the first check, because this means a reduced test coverage for this bug. So instead, I added another user with just the permission to open the form. Also, I made sure that user 1 is logged out after changing the entity's translatability.
Comment #8
Maouna CreditAttribution: Maouna at bio.logis Genetic Information Management GmbH commentedComment #9
k4v CreditAttribution: k4v as a volunteer commentedComment #10
alexpottThere should be an issue summary so that people know what is being fixed.
We're in a loop here we should get the service outside of the loop.
Changing this is not really necessary for the fix - seems unnecessarily disruptive for the fix.
Comment #11
amateescu CreditAttribution: amateescu for Pfizer, Inc. commented#10.1: Fixed.
#10.2: I think you looked only at the interdiff, the change there is for the new assertion method added by this patch, so there is no disruption :)
Wrote an issue summary and putting back to RTBC because my change is really minor.
Comment #12
tstoecklerRTBC++, thanks @alexpott for your never-failing eagle eyes and @amateescu for the quick fix! Awesome.
Comment #13
alexpottCommitted and pushed daea0bf to 8.4.x and 5552eef to 8.3.x. Thanks!
I credited myself for review comments that resulted in changes to the patch.
Comment #16
alexpottAlso backported to 8.3.x because I cannot see any BC implications to this bugfix.