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.
I'm calling this from another module, on an entity type that doesn't have entity translation enabled.
I'm getting TRUE from entity_translation_enabled_bundle()
every time. Because of the return empty($bundle_callback)
line.
To me this looks like a straight up issue with the code, if an entity translation bundle callback is not defined, this means entity translation is not enabled on the bundle. But the return empty($bundle_callback)
will return TRUE.
Comment | File | Size | Author |
---|---|---|---|
#8 | entity_translation-improve_documentation-for-bundle-callback_2185523-8448029.patch | 1.72 KB | Leon Kessler |
Comments
Comment #1
Leon Kessler CreditAttribution: Leon Kessler commentedPatch attached.
Comment #2
plachIIRC there can be entity types that do not define a bunde callback, but nonetheless can be eabled for translation. The current patch does not seem to support this use case.
Comment #3
Leon Kessler CreditAttribution: Leon Kessler commentedOkay, I didn't read the docs properly
In entity_translation.api.php:
So this makes the original code correct, but it assumes that you have already made the check for translations being enabled for the entity.
I think
entity_translation_enabled_bundle()
should check that the entity itself is enabled first. Although I understand there would be objections to this, as it would mean callingentity_translation_enabled()
, which itself callsentity_translation_enabled_bundle()
.Otherwise, I think this should at least be documented.
Comment #4
Leon Kessler CreditAttribution: Leon Kessler commentedComment #5
plachActually
entity_translation_enabled()
can perform also a bundle-level check if you specify it, so I guess we just need some docs improvements here.entity_translation_enabled_bundle()
was a later addition and I agree the whole DX is not ideal. We should probably state that you usually want to useentity_translation_enabled()
for this kind of checks.Comment #6
Leon Kessler CreditAttribution: Leon Kessler commentedOkay how about this?
Comment #7
plachAwesome, but since we are here what about updating also the docs of
hook_entity_info()
inentity_translation.api.php
? Do you think there is anything we can add to help clarifying this?Comment #8
Leon Kessler CreditAttribution: Leon Kessler commentedI think the documentation for
bundle callback
byhook_entity_info
is okay. But I think the language of it's default behaviour could be updated to match the format from the rest of the documentation.Have updated this in latest patch. What do you think?
Comment #9
plachLooks good, thanks!
Comment #11
plachCommitted and pushed, sorry for the delay.