content_translation_views_data_alter

content_translation_views_data_alter(array &$data)

Implements hook_views_data_alter().

File

core/modules/content_translation/content_translation.module, line 241
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::entityManager()->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',
        ],
      ];
    }
  }
}
doc_Drupal
2016-10-29 08:58:40
Comments
Leave a Comment

Please login to continue.