diff --git a/core/modules/content_translation/content_translation.admin.inc b/core/modules/content_translation/content_translation.admin.inc index 2f3bc0a22df..af5c2c4946d 100644 --- a/core/modules/content_translation/content_translation.admin.inc +++ b/core/modules/content_translation/content_translation.admin.inc @@ -87,13 +87,15 @@ function _content_translation_form_language_content_settings_form_alter(array &$ $entity_type = $entity_manager->getDefinition($entity_type_id); $storage_definitions = $entity_type instanceof ContentEntityTypeInterface ? $entity_manager->getFieldStorageDefinitions($entity_type_id) : array(); - $entity_type_translatable = $entity_type->isTranslatable(); + $entity_type_translatable = $content_translation_manager->isSupported($entity_type_id); foreach (entity_get_bundles($entity_type_id) as $bundle => $bundle_info) { // Here we do not want the widget to be altered and hold also the "Enable // translation" checkbox, which would be redundant. Hence we add this key - // to be able to skip alterations. + // to be able to skip alterations. Alter the title and display the message + // about UI integration. $form['settings'][$entity_type_id][$bundle]['settings']['language']['#content_translation_skip_alter'] = TRUE; if (!$entity_type_translatable) { + $form['settings'][$entity_type_id]['#title'] = t('@label (Translation is not supported).', array('@label' => $entity_type->getLabel())); continue; } diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index 9ab0bfd6cae..2751862d775 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -92,6 +92,14 @@ function content_translation_language_types_info_alter(array &$language_types) { * assumed. Every translation handler must implement * \Drupal\content_translation\ContentTranslationHandlerInterface. * + * By default, entity types that do not have a canonical link template cannot be + * enabled for translation. This can be overridden by setting the + * 'content_translation_ui_skip' key to true. When that key is set, the Content + * Translation module will not provide any UI for translating the entity type, + * and the entity type should implement its own UI. This is useful for (e.g.) + * entity types that are embedded into others for editing (which would not need + * a canonical link, but could still support translation). + * * To implement its business logic the content translation UI relies on various * metadata items describing the translation state. The default implementation * is provided by \Drupal\content_translation\ContentTranslationMetadataWrapper, diff --git a/core/modules/content_translation/src/ContentTranslationManager.php b/core/modules/content_translation/src/ContentTranslationManager.php index 11c93dab742..d0525e192cf 100644 --- a/core/modules/content_translation/src/ContentTranslationManager.php +++ b/core/modules/content_translation/src/ContentTranslationManager.php @@ -66,7 +66,7 @@ class ContentTranslationManager implements ContentTranslationManagerInterface { */ public function isSupported($entity_type_id) { $entity_type = $this->entityManager->getDefinition($entity_type_id); - return $entity_type->isTranslatable() && $entity_type->hasLinkTemplate('drupal:content-translation-overview'); + return $entity_type->isTranslatable() && ($entity_type->hasLinkTemplate('drupal:content-translation-overview') || $entity_type->get('content_translation_ui_skip')); } /** diff --git a/core/modules/content_translation/src/Tests/ContentTranslationUISkipTest.php b/core/modules/content_translation/src/Tests/ContentTranslationUISkipTest.php new file mode 100644 index 00000000000..d04be44fa80 --- /dev/null +++ b/core/modules/content_translation/src/Tests/ContentTranslationUISkipTest.php @@ -0,0 +1,44 @@ +drupalCreateUser(array( + 'translate any entity', + 'administer content translation', + 'administer languages' + )); + $this->drupalLogin($admin_user); + // Visit the content translation. + $this->drupalGet('admin/config/regional/content-language'); + + // Check the message regarding UI integration. + $this->assertText('Test entity - Translatable skip UI check'); + $this->assertText('Test entity - Translatable check UI (Translation is not supported)'); + } + +} diff --git a/core/modules/content_translation/tests/modules/content_translation_test/content_translation_test.info.yml b/core/modules/content_translation/tests/modules/content_translation_test/content_translation_test.info.yml new file mode 100644 index 00000000000..83ec8b8e62e --- /dev/null +++ b/core/modules/content_translation/tests/modules/content_translation_test/content_translation_test.info.yml @@ -0,0 +1,10 @@ +name: 'Content translation tests' +type: module +description: 'Provides content translation tests.' +package: Testing +version: VERSION +core: 8.x +dependencies: + - content_translation + - language + - entity_test diff --git a/core/modules/content_translation/tests/modules/content_translation_test/src/Entity/EntityTestTranslatableNoUISkip.php b/core/modules/content_translation/tests/modules/content_translation_test/src/Entity/EntityTestTranslatableNoUISkip.php new file mode 100644 index 00000000000..0c093229e6e --- /dev/null +++ b/core/modules/content_translation/tests/modules/content_translation_test/src/Entity/EntityTestTranslatableNoUISkip.php @@ -0,0 +1,32 @@ +