You are here

node_translation_hierarchy.module in Language Hierarchy 7

File

modules/node_translation_hierarchy/node_translation_hierarchy.module
View source
<?php

/**
 * Implements hook_page_alter().
 */
function node_translation_hierarchy_page_alter(&$page) {
  if (isset($page['content']['system_main']['translation_node_overview'])) {
    $languages = array_values(language_hierarchy_language_list());
    $translation_overview =& $page['content']['system_main']['translation_node_overview'];
    foreach ($languages as $index => $language) {
      $translation_overview['#rows'][$index][0] .= theme('indentation', array(
        'size' => $language->depth,
      ));
    }
  }
}

/**
 * Implements hook_menu_local_tasks_alter().
 */
function node_translation_hierarchy_menu_local_tasks_alter(&$data, $router_item, $root_path) {
  if ($router_item['path'] == 'node/%/edit') {
    $node = $router_item['map'][1];
    if (!empty($node->tnid) && translation_supported_type($node->type)) {
      $translations = translation_node_get_translations($node->tnid);
      $languages = language_list();
      $language_tabs = array();
      foreach ($translations as $langcode => $translation) {
        $tab = array();
        $tab['#theme'] = 'menu_local_task';
        $tab['#active'] = $langcode == $node->language;
        $tab['#link'] = array(
          'href' => "node/{$translation->nid}/edit",
          'title' => t($languages[$langcode]->name),
          'weight' => $languages[$langcode]->weight,
          'localized_options' => array(
            'language' => $languages[$langcode],
            'attributes' => array(
              'lang' => $langcode,
              'class' => array(
                'language-link',
              ),
            ),
          ),
        );
        $language_tabs[] = $tab;
      }
      if (count($language_tabs) > 1) {
        if (empty($data['tabs'][1])) {
          $data['tabs'][1] = array(
            'output' => array(),
          );
        }
        $data['tabs'][1]['output'] = array_merge($data['tabs'][1]['output'], $language_tabs);
        $data['tabs'][1]['count'] = count($data['tabs'][1]['output']);

        // Attach Language Hierarchy JS behaviours.
        language_hierarchy_attach_language_selector($data['tabs'][1]['output']);
      }
    }
  }
}

/**
 * Implements hook_views_api().
 */
function node_translation_hierarchy_views_api() {
  return array(
    'api' => 3,
    'path' => drupal_get_path('module', 'node_translation_hierarchy') . '/views',
  );
}