function _myu_language_dropdown($type = 'language') { if (drupal_multilingual()) { global $language_url; $path = drupal_is_front_page() ? '<front>' : $_GET['q']; //$type = 'language_url'; $languages = language_negotiation_get_switch_links($type, $path); $items = array(); foreach ($languages->links as $lang_code => $lang_options) { if ($lang_options['language']->language === $language_url->language) { // Icon for the selected language if (module_exists('languageicons')) { $icon = theme('languageicons_icon', array('language' => (object) array('language' => $lang_code), 'title' => $language_url->native)); } $active_language_text = $icon . '<span class="langname">' . strtoupper($language_url->language) . '</span><i class="fa fa-angle-down"></i>'; $active_language_link = l($active_language_text, 'javascript:;', array('html' => TRUE, 'external' => TRUE, 'attributes' => array('class' => 'dropdown-toggle', 'data-close-others' => 'true', 'data-hover' => 'dropdown', 'data-toggle' => 'dropdown'))); } else { if (!isset($lang_options['query'])) { $lang_options['query'] = drupal_get_query_parameters(); } $items[] = l($lang_options['title'], $lang_options['href'], $lang_options); } } $language_flag_list = theme('item_list', array('items' => $items, 'type' => 'ul', 'attributes' => array('class' => 'dropdown-menu dropdown-menu-default'))); return '<ul class="menu nav navbar-nav language"><li class="dropdown dropdown-language">' . $active_language_link . $language_flag_list . '</li></ul>'; } }
function _argoitia_language_list_2() { $abbrs = array("eu" => "Eus", "es" => "Cas", "en" => "Eng", "fr" => "Fr"); $path = drupal_is_front_page() ? '<front>' : $_GET['q']; $links = language_negotiation_get_switch_links('language', $path); global $language; // an array of list items $output = '<li><a href="#" style="padding-right: 7px;"><i class="glyphicon glyphicon-flag"></i></a></li>'; $items = array(); foreach ($links->links as $lang => $info) { //$name = $info['language']->native; //$name = $info['title']; //$name = $lang; $name = isset($abbrs[$lang]) ? $abbrs[$lang] : $lang; $href = isset($info['href']) ? $info['href'] : ''; $li_classes = array(''); $output .= '<li '; // if the global language is that of this item's language, add the active class if ($lang === $language->language) { $output .= 'class="active"'; } $output .= '>'; $link_classes = array(); $options = array('attributes' => array('class' => $link_classes), 'language' => $info['language'], 'html' => true); $link = l($name, $href, $options); $output .= $link . '</li>'; } // output return $output; }
public function switchLinks($path) { $links = \language_negotiation_get_switch_links('language', $path); return $links ? $links->links : NULL; }
/** * {@inheritdoc} */ public function submitForm(array &$form, array &$form_state) { $language_code = check_plain($form_state['values']['lang_dropdown_select']); $type = $form_state['values']['lang_dropdown_type']; $tohome = $form_state['values']['lang_dropdown_tohome']; $language_codes = language_list(); if (!array_key_exists($language_code, $language_codes)) { return; } $types = language_types_info(); if (!array_key_exists($type, $types)) { return; } $path = drupal_is_front_page() ? '<front>' : current_path(); $languages = language_negotiation_get_switch_links($type, $path); $language = $languages->links[$language_code]; $newpath = isset($language['href']) && $tohome == 0 ? $language['href'] : '<front>'; if (!isset($language['query'])) { $language['query'] = drupal_get_query_parameters(); } $form_state['redirect'] = array($newpath, $language); }
/** * {@inheritdoc} */ public function build() { // prevent erroneous configuration if ($this->configuration['widget'] == LANGDROPDOWN_MSDROPDOWN && !_lang_dropdown_get_msdropdown_path()) { return array(); } if ($this->configuration['widget'] == LANGDROPDOWN_CHOSEN && !_lang_dropdown_get_chosen_path()) { return array(); } if ($this->configuration['widget'] == LANGDROPDOWN_DDSLICK && !_lang_dropdown_get_ddslick_path()) { return array(); } $build = array(); $path = drupal_is_front_page() ? '<front>' : current_path(); list(, $type) = explode(':', $this->getPluginId()); $languages = language_negotiation_get_switch_links($type, $path); $user = \Drupal::currentUser(); $roles = $user->getRoles(); foreach ($languages->links as $langcode => $link) { $hide_language = true; foreach ($roles as $key => $role) { if (!isset($this->configuration['hidden_languages'][$role]) || !in_array($langcode, $this->configuration['hidden_languages'][$role])) { $hide_language = false; break; } } if ($hide_language) { unset($languages->links[$langcode]['href']); $languages->links[$langcode]['attributes']['class'][] = 'locale-untranslated'; } } if (empty($languages->links)) { return array(); } //$form = drupal_get_form('lang_dropdown_form', $languages, $type, $this->configuration); $lang_dropdown_form = new LanguageDropdownForm($languages->links, $type, $this->configuration); $form = \Drupal::formBuilder()->getForm($lang_dropdown_form); return array('lang_dropdown_form' => $form); if (!empty($languages->links)) { $build = array('#theme' => 'links__language_block', '#links' => $languages->links, '#attributes' => array('class' => array("language-dropdown-switcher-{$links->method_id}"))); } return $build; }