diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index da02771..97915a0 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -5,6 +5,7 @@ * Allows entities to be translated into different languages. */ +use Drupal\content_translation\ContentTranslationEntityType; use Drupal\Core\Access\AccessResult; use Drupal\Core\Entity\ContentEntityFormInterface; use Drupal\Core\Entity\ContentEntityInterface; @@ -92,23 +93,15 @@ function content_translation_language_types_info_alter(array &$language_types) { * \Drupal\content_translation\ContentTranslationHandler will be assumed. * Every translation handler must implement * \Drupal\content_translation\ContentTranslationHandlerInterface. - * - content_translation_ui_skip: By default, entity types that do not have a - * canonical link template cannot be enabled for translation. Setting this key - * to TRUE overrides that. 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). - * - content_translation_metadata: 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, which is - * relying on one field for each metadata item (field definitions are provided - * by the translation handler). Entity types needing to customize this - * behavior can specify an alternative class through the - * 'content_translation_metadata' key in the entity type definition. Every - * content translation metadata wrapper needs to implement - * \Drupal\content_translation\ContentTranslationMetadataWrapperInterface. + * - content_translation_ui_skip: See the $content_translation_ui_skip property + * of \Drupal\content_translation\ContentTranslationEntityType. + * - content_translation_metadata: See the $content_translation_metadata + * property of \Drupal\content_translation\ContentTranslationEntityType. + * + * In order to use content_translation_ui_skip or content_translation_metadata, + * the entity type must specify + * entity_type_class = "Drupal\content_translation\ContentTranslationEntityType" + * in its definition. * * If the entity paths match the default pattern above and there is no need for * an entity-specific translation handler, Content Translation will provide @@ -127,6 +120,9 @@ function content_translation_entity_type_alter(array &$entity_types) { } if (!$entity_type->get('content_translation_metadata')) { $entity_type->set('content_translation_metadata', 'Drupal\content_translation\ContentTranslationMetadataWrapper'); + // In order to use the content_translation_metadata property, we must + // switch the entity type class. + $entity_type->set('entity_type_class', ContentTranslationEntityType::class); } if (!$entity_type->getFormClass('content_translation_deletion')) { $entity_type->setFormClass('content_translation_deletion', '\Drupal\content_translation\Form\ContentTranslationDeleteForm'); diff --git a/core/modules/content_translation/src/ContentTranslationEntityType.php b/core/modules/content_translation/src/ContentTranslationEntityType.php new file mode 100644 index 0000000..7dc232d --- /dev/null +++ b/core/modules/content_translation/src/ContentTranslationEntityType.php @@ -0,0 +1,50 @@ +