content_translation_entity_base_field_info

content_translation_entity_base_field_info(EntityTypeInterface $entity_type)

Implements hook_entity_base_field_info().

File

core/modules/content_translation/content_translation.module, line 174
Allows entities to be translated into different languages.

Code

function content_translation_entity_base_field_info(EntityTypeInterface $entity_type) {
  /** @var \Drupal\content_translation\ContentTranslationManagerInterface $manager */
  $manager = \Drupal::service('content_translation.manager');
  $entity_type_id = $entity_type->id();
  if ($manager->isSupported($entity_type_id)) {
    $definitions = $manager->getTranslationHandler($entity_type_id)->getFieldDefinitions();
    $installed_storage_definitions = \Drupal::entityManager()->getLastInstalledFieldStorageDefinitions($entity_type_id);
    // We return metadata storage fields whenever content translation is enabled
    // or it was enabled before, so that we keep translation metadata around
    // when translation is disabled.
    // @todo Re-evaluate this approach and consider removing field storage
    //   definitions and the related field data if the entity type has no bundle
    //   enabled for translation, once base field purging is supported.
    //   See https://www.drupal.org/node/2282119.
    if ($manager->isEnabled($entity_type_id) || array_intersect_key($definitions, $installed_storage_definitions)) {
      return $definitions;
    }
  }
}
doc_Drupal
2016-10-29 08:58:36
Comments
Leave a Comment

Please login to continue.