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
Currently the NodeListBuilder::buildRow()
method tries to set the correct language for the node link. But before doing this, it checks if the language is available:
$options += ($langcode != LanguageInterface::LANGCODE_NOT_SPECIFIED && isset($languages[$langcode]) ? ['language' => $languages[$langcode]] : []);
Unfortunately $languages
is never initialized in this method, so the isset($languages[$langcode])
part of the condition is always FALSE
.
Proposed resolution
- Initialize
$languages
variable with\Drupal::languageManager()->getLanguages()
Remaining tasks
- Provide a patch to fix this issue
User interface changes
n/a
API changes
n/a
Data model changes
n/a
Comment | File | Size | Author |
---|---|---|---|
#13 | 2935654-13.patch | 1.85 KB | longwave |
Comments
Comment #2
hctom... and here is the proposed patch to fix this issue.
Comment #3
timmillwoodNice, find, and the patch looks great.
I guess we now need to test that the node title link gets the language option set.
Switching to needs work for that test.
Comment #11
longwaveRediscovered this following #3178534: Start running PHPStan on Drupal core (level 0)
I think we can just drop this code, as in the attached patch.
EntityBase::toUrl()
already sets the language of the URL:Therefore NodeListBuilder doesn't have do anything additional here, as the language option is already set correctly, and this is just dead code that can be removed.
Comment #12
longwaveComment #13
longwaveFix unused use statement.
Comment #14
joachim CreditAttribution: joachim at Factorial GmbH commentedLGTM.
Comment #15
hctomLooks good to me as well! I guess existing test coverage should be enough to ensure this change does not break anything.
Comment #16
larowlanCommitted e41394e and pushed to 9.3.x. Thanks!
As there is little risk of disruption here, backported to 9.2.x