You are here

function lingotek_entity_base_field_info in Lingotek Translation 3.0.x

Same name and namespace in other branches
  1. 8 lingotek.module \lingotek_entity_base_field_info()
  2. 8.2 lingotek.module \lingotek_entity_base_field_info()
  3. 4.0.x lingotek.module \lingotek_entity_base_field_info()
  4. 3.1.x lingotek.module \lingotek_entity_base_field_info()
  5. 3.2.x lingotek.module \lingotek_entity_base_field_info()
  6. 3.3.x lingotek.module \lingotek_entity_base_field_info()
  7. 3.4.x lingotek.module \lingotek_entity_base_field_info()
  8. 3.5.x lingotek.module \lingotek_entity_base_field_info()
  9. 3.6.x lingotek.module \lingotek_entity_base_field_info()
  10. 3.7.x lingotek.module \lingotek_entity_base_field_info()
  11. 3.8.x lingotek.module \lingotek_entity_base_field_info()

Implements hook_entity_base_field_info().

File

./lingotek.module, line 593
Implements Drupal-related hooks for the Lingotek Translation module.

Code

function lingotek_entity_base_field_info(EntityTypeInterface $entity_type) {

  // Taken from content_translation.

  /** @var \Drupal\content_translation\ContentTranslationManagerInterface $manager */
  $manager = \Drupal::service('content_translation.manager');

  /** @var \Drupal\lingotek\LingotekConfigurationServiceInterface $lingotek_config */
  $lingotek_config = \Drupal::service('lingotek.configuration');
  $entity_type_id = $entity_type
    ->id();
  if ($manager
    ->isEnabled($entity_type_id) && $lingotek_config
    ->isEnabled($entity_type_id)) {
    $definitions = \Drupal::entityTypeManager()
      ->getHandler($entity_type_id, 'lingotek')
      ->getFieldDefinitions();
    $installed_storage_definitions = \Drupal::service('entity.last_installed_schema.repository')
      ->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.
    if ($manager
      ->isEnabled($entity_type_id) || array_intersect_key($definitions, $installed_storage_definitions)) {
      return $definitions;
    }
  }
}