Issue #2018685 by yched: Remove field_is_translatable().
parent
7acc578c9d
commit
b6a53cadf5
|
@ -76,7 +76,7 @@ class CommentLanguageTest extends WebTestBase {
|
|||
$field = field_info_field('comment', 'comment_body');
|
||||
$field->translatable = TRUE;
|
||||
$field->save();
|
||||
$this->assertTrue(field_is_translatable('comment', $field), 'Comment body is translatable.');
|
||||
$this->assertTrue($field->isTranslatable(), 'Comment body is translatable.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -53,22 +53,19 @@ class FieldTranslationSynchronizer implements FieldTranslationSynchronizerInterf
|
|||
return;
|
||||
}
|
||||
|
||||
// @todo Use Entity Field API to retrieve field definitions.
|
||||
$instances = field_info_instances($entity_type, $entity->bundle());
|
||||
foreach ($instances as $field_name => $instance) {
|
||||
$field = $instance->getField();
|
||||
foreach ($entity as $field_name => $items) {
|
||||
$field_definition = $items->getFieldDefinition();
|
||||
|
||||
// Sync when the field is not empty, when the synchronization translations
|
||||
// setting is set, and the field is translatable.
|
||||
$translation_sync = $instance->getSetting('translation_sync');
|
||||
if (!$entity->get($field_name)->isEmpty() && !empty($translation_sync) && field_is_translatable($entity_type, $field)) {
|
||||
// Sync if the field is translatable, not empty, and the synchronization
|
||||
// setting is enabled.
|
||||
if ($field_definition->isTranslatable() && !$items->isEmpty() && $translation_sync = $field_definition->getSetting('translation_sync')) {
|
||||
// Retrieve all the untranslatable column groups and merge them into
|
||||
// single list.
|
||||
$groups = array_keys(array_diff($translation_sync, array_filter($translation_sync)));
|
||||
if (!empty($groups)) {
|
||||
$columns = array();
|
||||
foreach ($groups as $group) {
|
||||
$column_groups = $field->getSetting('column_groups');
|
||||
$column_groups = $field_definition->getSetting('column_groups');
|
||||
$info = $column_groups[$group];
|
||||
// A missing 'columns' key indicates we have a single-column group.
|
||||
$columns = array_merge($columns, isset($info['columns']) ? $info['columns'] : array($group));
|
||||
|
|
|
@ -30,9 +30,7 @@ use Drupal\field\FieldInterface;
|
|||
*
|
||||
* The available language codes for a particular field are returned by
|
||||
* field_available_languages(). Whether a field is translatable is determined by
|
||||
* calling field_is_translatable(), which checks the $field['translatable']
|
||||
* property returned by field_info_field() and whether the entity type the field
|
||||
* is attached to supports translation.
|
||||
* calling $field_definition->isTranslatable().
|
||||
*
|
||||
* By default, field_invoke_method() processes a field in all available
|
||||
* languages, unless it is given a language code suggestion. Based on that
|
||||
|
@ -93,7 +91,7 @@ function field_available_languages($entity_type, FieldInterface $field) {
|
|||
if (!isset($field_langcodes[$entity_type][$field_name])) {
|
||||
// If the field has language support enabled we retrieve an (alterable) list
|
||||
// of enabled languages, otherwise we return Language::LANGCODE_DEFAULT.
|
||||
if (field_is_translatable($entity_type, $field)) {
|
||||
if ($field->isTranslatable()) {
|
||||
$langcodes = field_content_languages();
|
||||
// Let other modules alter the available languages.
|
||||
$context = array('entity_type' => $entity_type, 'field' => $field);
|
||||
|
@ -152,24 +150,6 @@ function field_content_languages() {
|
|||
return array_keys(language_list(Language::STATE_ALL));
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a field has language support.
|
||||
*
|
||||
* A field has language support enabled if its 'translatable' property is set to
|
||||
* TRUE, and its entity type has at least one translation handler registered.
|
||||
*
|
||||
* @param $entity_type
|
||||
* The type of the entity the field is attached to.
|
||||
* @param $field
|
||||
* A field data structure.
|
||||
*
|
||||
* @return
|
||||
* TRUE if the field can be translated.
|
||||
*/
|
||||
function field_is_translatable($entity_type, FieldInterface $field) {
|
||||
return $field->isTranslatable() && field_has_translation_handler($entity_type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a module is registered as a translation handler for a given entity.
|
||||
*
|
||||
|
|
|
@ -252,7 +252,7 @@ class Field extends FieldPluginBase {
|
|||
|
||||
// Filter by langcode, if field translation is enabled.
|
||||
$field = $this->field_info;
|
||||
if (field_is_translatable($entity_type, $field) && !empty($this->view->display_handler->options['field_langcode_add_to_query'])) {
|
||||
if ($field->isTranslatable() && !empty($this->view->display_handler->options['field_langcode_add_to_query'])) {
|
||||
$column = $this->tableAlias . '.langcode';
|
||||
// By the same reason as field_language the field might be Language::LANGCODE_NOT_SPECIFIED in reality so allow it as well.
|
||||
// @see this::field_langcode()
|
||||
|
@ -855,7 +855,7 @@ class Field extends FieldPluginBase {
|
|||
* according to the settings.
|
||||
*/
|
||||
function field_langcode(EntityInterface $entity) {
|
||||
if (field_is_translatable($entity->entityType(), $this->field_info)) {
|
||||
if ($this->field_info->isTranslatable()) {
|
||||
$default_langcode = language_default()->id;
|
||||
$langcode = str_replace(
|
||||
array('***CURRENT_LANGUAGE***', '***DEFAULT_LANGUAGE***'),
|
||||
|
|
Loading…
Reference in New Issue