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.
The current views query alteration just joins in the revision data table, but without adding a join condition on languages. This results in a multiplication of each entity result row with the number of available languages.
Comment | File | Size | Author |
---|---|---|---|
#14 | interdiff-14.txt | 2.99 KB | amateescu |
#14 | 3065212-14.patch | 7.5 KB | amateescu |
#11 | interdiff_9-11.txt | 773 bytes | leolandotan |
#11 | 3065212-11.patch | 5.16 KB | leolandotan |
#9 | 3065212-9.patch | 5.12 KB | amateescu |
Comments
Comment #2
pmelab CreditAttribution: pmelab at Amazee Labs commentedComment #3
pmelab CreditAttribution: pmelab at Amazee Labs commentedFirst patch with test case.
Comment #4
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedIt took me a while to figure it out, but
extra
can be a simple (string) expression instead of an array, in which case it will be added as-is. So we can replace this and the newrevision_table
join plugin with'extra' => "$table.langcode = $relationship.langcode",
:)Additionally, we need to do this only if the entity type has a
langcode
entity key, so we need to pass the$entity_type
object fromensureRevisionTable()
togetRevisionTableJoin()
and only add the extra join condition if$entity_type->hasKey('langcode')
.Let's move this line under the one which creates the content type, for better readability :)
The test runner executes the
setUp()
method for each test method, so this is not needed. This means we can also remove theprotected $languageManager
member added above.Comment #5
pmelab CreditAttribution: pmelab at Amazee Labs commentedImplemented suggestions by @amateescu. Thanks!
Comment #6
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedLooks great :D Let's see if the testbot agrees.
Comment #7
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedOk, the testbot is happy, here's also a test-only patch to prove the failure.
Comment #9
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedNot sure what happened with the patch from #7, it applies fine locally on both 8.7.x and 8.8.x, let's try again :)
Edit: Oh, I queued that test on the Drupal 7.x branch :/
Comment #10
catchI think we should be checking EntityTypeInterface::isTranslatable() here instead of the langcode key directly.
It's the same check in practice (unless we checked if bundles were translatable but that's not really reliable for views).
Comment #11
leolandotan CreditAttribution: leolandotan as a volunteer and at Promet Source commentedHi guys,
I added the recommended change from @catch regarding checking for EntityTypeInterface::isTranslatable(). I hope everything is in order.
Thank you!
Comment #12
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedNice, thanks for the update :)
Comment #13
catchSorry that change got me thinking, also thanks @plach who checked this was sensible.
At the moment, the logic of the patch is that if the entity type supports translation, then it should join, but this is resulting in a join in at least two cases where it's not necessary:
1. The site only has one language configured.
2. The site has multiple languages configured, but the entity type we're working with has no bundles with translation enabled.
I think we should do all three checks here - the site is multilingual, the entity type is translatable, at least one bundle has translation enabled.
There's a third issue that plach pointed out, is that bundles where translation has been disabled may have old translations in the database. This may mean we can't rely on 'at least one bundle has translation enabled' but we could check that the site is multilingual.
Comment #14
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThat's not entirely accurate :) We need to perform the join every time to ensure that we select a possible workspace-specific revision, and this patch is only about adding an additional
langcode
condition to that join.That's a really nice point. Since we can't rely on any bundle being translatable or not, I only added the "site is multilingual" check.
Comment #15
catchOh good point extra condition not extra join.
Committed 88fede1 and pushed to 8.8.x, and cherry-picked to 8.7.x. Thanks!