Problem/Motivation
Running \Drupal\Tests\language\Kernel\Views\FilterLanguageTest() on PHP 8.0 fails because it does not return the ***LANGUAGE_language_content*** language.
Steps to reproduce
See https://www.drupal.org/pift-ci-job/1855374
OR change \Drupal\views\Plugin\views\PluginBase::listLanguages() from
if (isset($type['name']) && !isset($list[$id]) && in_array($id, $current_values)) {
to
if (isset($type['name']) && !isset($list[$id]) && in_array($id, $current_values, TRUE)) {
Proposed resolution
Comparison of strings with numbers is different https://wiki.php.net/rfc/string_to_number_comparison
Ensure we make the comparison we expect to in \Drupal\views\Plugin\views\PluginBase::listLanguages()
@todo Discuss the impacts of making this change.
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Comments
Comment #2
alexpottComment #3
andypostAs I see only
\Drupal\views\Plugin\views\filter\LanguageFilter::getValueOptions()using to pass 2nd argument to this method, probably it's set of configured values in filter, and its tests pass bothComment #5
andypostquick debug shows that
$current_valuesareatm
***LANGUAGE_language_content***is ID whenin_array($id, $current_values) !== in_array($id, $current_values, TRUE)Comment #6
andypostAdded to summary https://wiki.php.net/rfc/string_to_number_comparison
Because
in_array()looking for string in number indexed arrayhttps://3v4l.org/D3n5g
Comment #7
andypostAs https://3v4l.org/D3n5g shows that old compare was wrong
Comment #8
alexpott@andypost asked a good question in slack - why is $current_values in \Drupal\views\Plugin\views\PluginBase::listLanguages() equal to [0 => 0].
Well we get the same error if we make the following change. And then $current_values is equal to [0 => 'en'] and then [0 => 'xx-lolspeak'] in the test which makes way more sense.
Comment #9
alexpottHere's #8 combined with #2 which I think is the correct fix.
Comment #10
alexpottOr in the test should we change from
to
... I dunno.
Comment #11
alexpottThe more I look at it the more I'm convinced we're setting the value wrong in this test. Let's do that instead of #9.
Comment #12
alexpottYeah if I create a filter on a language field the config looks like this:
So I think this test has been setting the value wrong all this time.
Comment #13
andypostGit history shows that in related
array_keys()been added - #2420737: Differences in dynamic language names are confusing in views, content, etc.Comment #14
andypostLooks usage in
\Drupal\views\Plugin\views\display\DisplayPluginBase::buildRenderingLanguageOptions()is not affected as values are passed properlyComment #17
andypostBack to rtbc!
Comment #20
catchCommitted f113289 and pushed to 9.2.x. Thanks! Cherry-picked to 9.1.x too.