function ContentTranslationHooks::viewsDataAlter

Implements hook_views_data_alter().

Attributes

#[Hook('views_data_alter')]

File

core/modules/content_translation/src/Hook/ContentTranslationHooks.php, line 318

Class

ContentTranslationHooks
Hook implementations for content_translation.

Namespace

Drupal\content_translation\Hook

Code

public function viewsDataAlter(array &$data) : void {
  // 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' => $this->t('Link to translate @entity_type_label', $t_arguments),
          'help' => $this->t('Provide a translation link to the @entity_type_label.', $t_arguments),
          'id' => 'content_translation_link',
        ],
      ];
    }
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.