diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index e8987e2..3e34150 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -438,9 +438,7 @@ public function getAdminRouteInfo($entity_type, $bundle) { /** * Gets an array of content entity field definitions. * - * If a bundle is passed, fields specific to this bundle are included. Entity - * fields are always multi-valued, so 'list' is TRUE for each returned field - * definition. + * If a bundle is passed, fields specific to this bundle are included. * * @param string $entity_type * The entity type to get field definitions for. Only entity types that @@ -492,8 +490,7 @@ public function getFieldDefinitions($entity_type, $bundle = NULL) { $hooks = array('entity_field_info', $entity_type . '_field_info'); $this->moduleHandler->alter($hooks, $this->entityFieldInfo[$entity_type], $entity_type); - // Enforce field definitions to be objects, and fields to be - // untranslatable by default. + // Enforce field definitions to be objects. $entity_info = $this->getDefinition($entity_type); $keys = array_intersect_key(array_filter($entity_info['entity_keys']), array_flip(array('id', 'revision', 'uuid', 'bundle'))); $untranslatable_fields = array_flip(array('langcode') + $keys); @@ -510,9 +507,6 @@ public function getFieldDefinitions($entity_type, $bundle = NULL) { if (isset($untranslatable_fields[$field_name]) && $definition->isFieldTranslatable()) { throw new \LogicException(format_string('The @field field cannot be translatable.', array('@field' => $definition->getFieldLabel()))); } - if ($definition->isFieldTranslatable()) { - $definition->setTranslatable(FALSE); - } } } diff --git a/core/lib/Drupal/Core/Entity/Field/FieldDefinition.php b/core/lib/Drupal/Core/Entity/Field/FieldDefinition.php index dd9ef34..b2cf431 100644 --- a/core/lib/Drupal/Core/Entity/Field/FieldDefinition.php +++ b/core/lib/Drupal/Core/Entity/Field/FieldDefinition.php @@ -307,6 +307,9 @@ public static function createFromOldStyleDefinition(array $definition) { if (isset($definition['constraints'])) { $item_definition->setConstraints($definition['constraints']); } + if (isset($definition['translatable']) && $definition['translatable']) { + $field_definition->setTranslatable($definition['translatable']); + } $field_definition->setItemDefinition($item_definition); return $field_definition; } diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index b2a83b1..337efd4 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -102,7 +102,7 @@ function _content_translation_form_language_content_settings_form_alter(array &$ // translation. // @todo Remove this special casing as soon as configurable and // base field definitions are "unified". - if (!empty($definition['configurable']) && ($field = FieldService::fieldInfo()->getField($entity_type, $field_name))) { + if ($definition->isFieldConfigurable() && ($field = FieldService::fieldInfo()->getField($entity_type, $field_name))) { $instance = FieldService::fieldInfo()->getInstance($entity_type, $bundle, $field_name); $form['settings'][$entity_type][$bundle]['fields'][$field_name] = array( '#label' => $instance->getFieldLabel(), diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index d67c7f9..f92e559 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -145,8 +145,15 @@ function content_translation_entity_field_info_alter(&$info, $entity_type) { foreach ($fields as $name => $translatable) { foreach ($keys as $key) { if (isset($info[$key][$name])) { - $info[$key][$name]['translatable'] = (bool) $translatable; - break; + $translatable = (bool) $translatable; + // @todo: Remove array check after all base fields have been + // converted to object. + if (is_array($info[$key][$name])) { + $info[$key][$name]['translatable'] = $translatable; + } + elseif (is_object($info[$key][$name])) { + $info[$key][$name]->setTranslatable($translatable); + } } } } diff --git a/core/modules/field/lib/Drupal/field/Entity/Field.php b/core/modules/field/lib/Drupal/field/Entity/Field.php index da6129f..150311c 100644 --- a/core/modules/field/lib/Drupal/field/Entity/Field.php +++ b/core/modules/field/lib/Drupal/field/Entity/Field.php @@ -578,6 +578,20 @@ public function isFieldTranslatable() { } /** + * Sets whether the field is translatable. + * + * @param bool $translatable + * Whether the field is translatable. + * + * @return \Drupal\field\Entity\Field + * The object itself for chaining. + */ + public function setTranslatable($translatable) { + $this->translatable = $translatable; + return $this; + } + + /** * {@inheritdoc} */ public function getFieldLabel() {