Same name and namespace in other branches
  1. 8.9.x core/modules/content_translation/content_translation.module \content_translation_views_data_alter()
  2. 9 core/modules/content_translation/content_translation.module \content_translation_views_data_alter()

Implements hook_views_data_alter().

File

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

Code

function content_translation_views_data_alter(array &$data) {

  // Add the content translation entity link definition to Views data for entity
  // types having translation enabled.
  $entity_types = \Drupal::entityTypeManager()
    ->getDefinitions();

  /** @var \Drupal\content_translation\ContentTranslationManagerInterface $manager */
  $manager = \Drupal::service('content_translation.manager');
  foreach ($entity_types as $entity_type_id => $entity_type) {
    $base_table = $entity_type
      ->getBaseTable();
    if (isset($data[$base_table]) && $entity_type
      ->hasLinkTemplate('drupal:content-translation-overview') && $manager
      ->isEnabled($entity_type_id)) {
      $t_arguments = [
        '@entity_type_label' => $entity_type
          ->getLabel(),
      ];
      $data[$base_table]['translation_link'] = [
        'field' => [
          'title' => t('Link to translate @entity_type_label', $t_arguments),
          'help' => t('Provide a translation link to the @entity_type_label.', $t_arguments),
          'id' => 'content_translation_link',
        ],
      ];
    }
  }
}