diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php index 9255b34..c76dd41 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php @@ -76,7 +76,7 @@ function setUp() { $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.'); } /** diff --git a/core/modules/content_translation/lib/Drupal/content_translation/FieldTranslationSynchronizer.php b/core/modules/content_translation/lib/Drupal/content_translation/FieldTranslationSynchronizer.php index 8486b16..4efde31 100644 --- a/core/modules/content_translation/lib/Drupal/content_translation/FieldTranslationSynchronizer.php +++ b/core/modules/content_translation/lib/Drupal/content_translation/FieldTranslationSynchronizer.php @@ -53,22 +53,19 @@ public function synchronizeFields(ContentEntityInterface $entity, $sync_langcode 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)); diff --git a/core/modules/field/field.multilingual.inc b/core/modules/field/field.multilingual.inc index 8565e96..d5d058a 100644 --- a/core/modules/field/field.multilingual.inc +++ b/core/modules/field/field.multilingual.inc @@ -30,9 +30,7 @@ * * 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); @@ -153,24 +151,6 @@ function field_content_languages() { } /** - * 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. * * If no handler is passed, the function simply checks if there is any diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index 9bbb6ca..2a3b8fd 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php @@ -252,7 +252,7 @@ public function query($use_groupby = FALSE) { // 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 @@ protected function addSelfTokens(&$tokens, $item) { * 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***'),