Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291167

Decide what to do with field_is_translatable()

$
0
0

Current code is:

<?php
function field_is_translatable($entity_type, $field) {
  return
$field['translatable'] && field_has_translation_handler($entity_type);
}

function
field_has_translation_handler($entity_type, $handler = NULL) {
 
$info = entity_get_info($entity_type);
  return !empty(
$info['translatable']);
}
?>

Those two should most probably be methods somewhere - but where ? :-)

For field_is_translatable(), this could be:
- on the FieldItem class:
When those objects exist, there is an $entity to work with
OTOH, since those objects are the *values* themselves (possibly already "translated") - does it make sense for them to say "I'm translatable" ?
- on the Field config entity - then, works only for configurable fields
- on the FieldDefinitionInterface being introduced in #1950632: Create a FieldDefinitionInterface, decoupled from $field and $instance config entities, and use it for formatters and widgets
That one already has an isTranslatable() method, but it only reflects the "$field['translatable']" part (it specifies it should be translatable), not the "&& field_has_translation_handler($entity_type)" part ("it actually *is* translatable according to the rest of the site i18n setup")

Also, it seems that EntityNG::getTranslationLanguages() has some related / similar-but-not-quite-(?) logic to determine the list of languages that appear in an entity.

So yep, some cleanup / unification might be helpful here.


Viewing all articles
Browse latest Browse all 291167

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>