-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#1116 - add language option to the entity buffer #1117
base: 8.x-4.x
Are you sure you want to change the base?
#1116 - add language option to the entity buffer #1117
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I think we could do that. The language adds another dimension to the buffer key I think, so we could split up the buckets per language as well. Loaded entities are cached and getting another translation should not trigger database queries (as far as I can see), so would make sense.
The only downside then is that if you use different entities and different languages that the entity load is done multiple times per language.
And instead of touching the EntityBuffer we could make an EntityLanguageBuffer, like we do for UUID and revisions?
Then again I don't fully understand your use case - can you use the EntityLoad data producer which has language support already?
@@ -55,6 +58,7 @@ protected function getBufferId($item) { | |||
*/ | |||
public function resolveBufferArray(array $buffer) { | |||
$type = reset($buffer)['type']; | |||
$language = reset($buffer)['language']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently the buffer is keyed by entity type. Do we also need to key it by language as well? You are assuming that all items in this buffer want the same language. Maybe that is an ok assumption to make? Not sure here.
if (!empty($entities[$current])) { | ||
array_push($carry, $entities[$current]); | ||
$entity = $language ? $entities[$current]->getTranslation($language) : $entities[$current]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will throw fatal errors if the entity type is not translatable. That is also why PHPStan is complaining. Maybe that is ok and we don't care? We could already throw an exception if a language is passed in the add() method on not translatable entity types.
The use case for this is not entirely clear to me. The We can see this in the SQL storage implementation which loads translations from shared tables while converting the results from storage records to entities will also query the translation tables to fetch translation data: https://git.drupalcode.org/project/drupal/-/blob/10.1.x/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php#L498 We can also see that calling Unless I'm missing something we should probably close this as a won't fix, and the correct usage would be to call |
bc35d60
to
b06b46e
Compare
Fixes #1116