You are here

function language_hierarchy_views_data_alter in Language Hierarchy 8

Same name and namespace in other branches
  1. 2.x language_hierarchy.views.inc \language_hierarchy_views_data_alter()

Implements hook_views_data_alter().

File

./language_hierarchy.views.inc, line 10
Views hooks for the Language Hierarchy module.

Code

function language_hierarchy_views_data_alter(&$data) {

  // Add filters for language with fallback, for content translations.
  foreach (\Drupal::entityTypeManager()
    ->getDefinitions() as $entity_type_id => $entity_type) {
    if ($entity_type
      ->hasHandlerClass('views_data')) {
      if ($lang_key = $entity_type
        ->getKey('langcode')) {
        $tables = [];
        if ($current_data_table = $entity_type
          ->getDataTable()) {
          $tables[] = $current_data_table;
        }
        if ($revision_data_table = $entity_type
          ->getRevisionDataTable()) {
          $tables[] = $revision_data_table;
        }
        foreach ($tables as $table) {
          if (!empty($data[$table][$lang_key]['filter']['id']) && $data[$table][$lang_key]['filter']['id'] === 'language') {
            $data[$table]['language_hierarchy_content_language_fallback_limited_' . $lang_key] = [
              'title' => t('Most relevant translation (using fallback)'),
              'help' => t('Shows only the translation that is most specific to the content language.'),
              'filter' => array(
                'id' => 'language_hierarchy_content_language_fallback_limited',
              ),
              'real field' => $lang_key,
              'entity field' => $lang_key,
            ];
          }
        }
      }
    }
  }
}