array( 'variables' => array('language' => NULL, 'title' => NULL), ), 'languageicons_place' => array( 'variables' => array('text' => NULL, 'icon' => NULL, 'separator' => ' '), ), ); } /** * Implements hook_help(). * * @todo The @handbook link needs to change to a module specific one. */ function languageicons_help($path, $arg) { switch ($path) { case 'admin/help#languageicons': $output = '
' . t('This module manages language icons for multilingual sites:') . '
'; $output .= '' . t('For more information, please see the online handbook section.', array('@handbook' => 'http://drupal.org/node/133977')) . '
'; return $output; case 'admin/config/regional/language/icons': $output = '' . t('To enable multilingual support for specific content types go to configure content types.', array('@configure_content_types' => url('admin/structure/types'))) . '
'; return $output; } } /** * Implements hook_menu(). */ function languageicons_menu() { $items['admin/config/regional/language/icons'] = array( 'title' => 'Icons', 'page callback' => 'drupal_get_form', 'page arguments' => array('languageicons_admin_settings'), 'weight' => 10, 'type' => MENU_LOCAL_TASK, 'access arguments' => array('administer languages'), 'file' => 'languageicons.admin.inc', ); return $items; } /** * Implements hook_language_switch_links_alter(). * * Adds language icons to language switcher block links. * * @todo Figure out a way to either ignore node links or specifically target * them here. See http://drupal.org/node/1005144 for more info. */ function languageicons_language_switch_links_alter(array &$links, $type, $path) { if (variable_get('languageicons_show_block', 1)) { foreach (array_keys($links) as $langcode) { languageicons_link_add($links[$langcode]); } } } /** * Implements hook_node_view_alter(). * * Adds language icons to node links. */ function languageicons_node_view_alter(&$build) { $node = $build['#node']; if (variable_get('languageicons_show_node', 1) && (!empty($node->tnid)) && $translations = module_invoke('translation', 'node_get_translations', $node->tnid)) { $links = &$build['links']['translation']['#links']; foreach ($translations as $langcode => $translation) { $index = 'translation_' . $langcode; if (!empty($links[$index])) { languageicons_link_add($links[$index]); } } } } /** * Add language icon to link. * * The language icon may be a different language as the destination page, can be passed in 'language_icon'. */ function languageicons_link_add(&$link, $title = NULL) { $language = isset($link['language_icon']) ? $link['language_icon'] : $link['language']; $title = $title ? $title : $link['title']; $icon = theme('languageicons_icon', array( 'language' => $language, 'title' => $title, )); if ($icon) { $link['title'] = theme('languageicons_place', array( 'text' => $link['title'], 'icon' => $icon, )); $link['html'] = TRUE; } } /** * Theme language icon. * * This function can be overridden for no language icons. * * @seealso theme_image() */ function theme_languageicons_icon($variables) { $language = $variables['language']; $title = $variables['title']; if ($path = variable_get('languageicons_path', drupal_get_path('module', 'languageicons') . '/flags/*.png')) { $title = $title ? $title : $language->native; // Build up $image for theme_image() consumption. $image = array( 'path' => str_replace('*', $language->language, $path), 'alt' => $title, 'title' => $title, 'attributes' => array( 'class' => 'language-icon', ), ); if ($size = variable_get('languageicons_size', '16x12')) { list($width, $height) = explode('x', $size); $image += array('width' => $width, 'height' => $height); } return theme('image', $image); } } /** * Theme language icon and text. * * @ingroup themeable */ function theme_languageicons_place($variables) { $text = $variables['text']; $icon = $variables['icon']; $separator = $variables['separator']; switch (variable_get('languageicons_placement', 'before')) { case 'after': return $text . $separator . $icon; case 'replace': return $icon; case 'before': default: return $icon . $separator . $text; } }