You are here

public function EntityTranslationDefaultHandler::localTasksAlter in Entity Translation 7

Overrides EntityTranslationHandlerInterface::localTasksAlter

See also

EntityTranslationHandlerInterface::localTasksAlter()

File

includes/translation.handler.inc, line 1637
Default translation handler for the translation module.

Class

EntityTranslationDefaultHandler
Class implementing the default entity translation behaviours.

Code

public function localTasksAlter(&$data, $router_item, $root_path) {
  $translations = $this
    ->getTranslations();
  if (count($translations->data) > 0) {
    $languages = language_list();
    $form_langcode = $this
      ->getActiveLanguage();
    $language_tabs = array();
    if ($this
      ->getSourceLanguage()) {
      foreach ($data['tabs'][1]['output'] as $index => &$add_tab) {
        if ($add_tab['#link']['path'] == $root_path) {
          $add_tab['#link']['title'] = $languages[$form_langcode]->name;
          $add_tab['#link']['weight'] = $languages[$form_langcode]->weight;
          $add_tab['#active'] = TRUE;
          $add_tab['#language_tab'] = TRUE;
          $language_tabs[] = $add_tab;
          unset($data['tabs'][1]['output'][$index]);
          break;
        }
      }
    }
    foreach ($translations->data as $langcode => $translation) {
      if ($this
        ->getTranslationAccess($langcode)) {
        $links = $this
          ->languageSwitchLinks($this
          ->getEditPath($langcode));
        $link = !empty($links->links[$langcode]) ? $links->links[$langcode] : array();
        if (isset($link['href'])) {
          $tab = array();
          $tab['#theme'] = 'menu_local_task';
          $tab['#active'] = $langcode == $form_langcode;
          $tab['#language_tab'] = TRUE;
          $tab['#link'] = array(
            'href' => $link['href'],
            'title' => t($languages[$langcode]->name),
            'weight' => $languages[$langcode]->weight,
            'localized_options' => $link,
          ) + $router_item;
          $language_tabs[] = $tab;
        }
      }
    }

    // Reorder tabs to make the add tab respect language weights.
    usort($language_tabs, array(
      $this,
      'translationTabSort',
    ));

    // Merge the reordered language tabs into the second level tabs.
    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']);
    }
  }
}