You are here

function lingotek_entity_base_field_info in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 lingotek.module \lingotek_entity_base_field_info()
  2. 4.0.x lingotek.module \lingotek_entity_base_field_info()
  3. 3.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 397
lingotek.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::entityManager()
      ->getHandler($entity_type_id, 'lingotek')
      ->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;
    }
  }
}