diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index df0d8c4a6f5..03ed352dc6d 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2293,7 +2293,7 @@ function _drupal_bootstrap_configuration() { // Register explicit vendor namespaces. $loader->registerNamespaces(array( - // All Symfony-borrowed code lives in /core/includes/Symfony. + // All Symfony-borrowed code lives in /core/vendor/Symfony. 'Symfony' => DRUPAL_ROOT . '/core/vendor', )); // Register the Drupal namespace for classes in core as a fallback. @@ -2303,7 +2303,7 @@ function _drupal_bootstrap_configuration() { // namespace match based on a string comparison. It further allows modules to // register/overload namespaces in Drupal core. $loader->registerNamespaceFallbacks(array( - // All Drupal-namespaced code in core lives in /core/includes/Drupal. + // All Drupal-namespaced code in core lives in /core/lib/Drupal. 'Drupal' => DRUPAL_ROOT . '/core/lib', )); } @@ -2653,53 +2653,45 @@ function language_types() { } /** - * Returns a list of installed languages, indexed by the specified key. + * Returns a list of configured languages. * - * @param $field - * (optional) The field to index the list with. + * @param $only_enabled + * (optional) Whether to return only enabled languages. * * @return - * An associative array, keyed on the values of $field. - * - If $field is 'weight' or 'enabled', the array is nested, with the outer - * array's values each being associative arrays with language codes as - * keys and language objects as values. - * - For all other values of $field, the array is only one level deep, and - * the array's values are language objects. + * An associative array of languages, keyed by the language code, ordered by + * weight ascending and name ascending. */ -function language_list($field = 'langcode') { +function language_list($only_enabled = FALSE) { $languages = &drupal_static(__FUNCTION__); - // Init language list + // Initialize master language list. if (!isset($languages)) { + // Initialize local language list caches. + $languages = array('all' => array(), 'enabled' => array()); + + // Fill in master language list based on current configuration. $default = language_default(); if (language_multilingual() || module_exists('language')) { - $languages['langcode'] = db_query('SELECT * FROM {language} ORDER BY weight ASC, name ASC')->fetchAllAssoc('langcode'); + // Use language module configuration if available. + $languages['all'] = db_query('SELECT * FROM {language} ORDER BY weight ASC, name ASC')->fetchAllAssoc('langcode'); } else { - // No locale module, so use the default language only. - $languages['langcode'][$default->langcode] = $default; + // No language module, so use the default language only. + $languages['all'][$default->langcode] = $default; } - // Initialize default property so callers have an easy reference and - // can save the same object without data loss. - foreach ($languages['langcode'] as $langcode => $language) { - $languages['langcode'][$langcode]->default = ($langcode == $default->langcode); - } - } - - // Return the array indexed by the right field - if (!isset($languages[$field])) { - $languages[$field] = array(); - foreach ($languages['langcode'] as $lang) { - // Some values should be collected into an array - if (in_array($field, array('enabled', 'weight'))) { - $languages[$field][$lang->$field][$lang->langcode] = $lang; - } - else { - $languages[$field][$lang->$field] = $lang; + // Initialize default property so callers have an easy reference and can + // save the same object without data loss. Also fill in the filtered list + // of enabled languages only. + foreach ($languages['all'] as $langcode => $language) { + $languages['all'][$langcode]->default = ($langcode == $default->langcode); + if ($language->enabled) { + $languages['enabled'][$langcode] = $languages['all'][$langcode]; } } } - return $languages[$field]; + + return $only_enabled ? $languages['enabled'] : $languages['all']; } /** @@ -3205,29 +3197,29 @@ function registry_update() { * * Example: * @code - * function language_list($field = 'langcode') { - * $languages = &drupal_static(__FUNCTION__); - * if (!isset($languages)) { + * function example_list($field = 'default') { + * $examples = &drupal_static(__FUNCTION__); + * if (!isset($examples)) { * // If this function is being called for the first time after a reset, * // query the database and execute any other code needed to retrieve - * // information about the supported languages. + * // information. * ... * } - * if (!isset($languages[$field])) { + * if (!isset($examples[$field])) { * // If this function is being called for the first time for a particular * // index field, then execute code needed to index the information already - * // available in $languages by the desired field. + * // available in $examples by the desired field. * ... * } * // Subsequent invocations of this function for a particular index field * // skip the above two code blocks and quickly return the already indexed * // information. - * return $languages[$field]; + * return $examples[$field]; * } - * function locale_translate_overview_screen() { - * // When building the content for the translations overview page, make - * // sure to get completely fresh information about the supported languages. - * drupal_static_reset('language_list'); + * function examples_admin_overview() { + * // When building the content for the overview page, make sure to get + * // completely fresh information. + * drupal_static_reset('example_list'); * ... * } * @endcode diff --git a/core/includes/language.inc b/core/includes/language.inc index d1d2eaf1bbc..46280532597 100644 --- a/core/includes/language.inc +++ b/core/includes/language.inc @@ -329,9 +329,8 @@ function language_provider_invoke($provider_id, $provider = NULL) { if (!isset($results[$provider_id])) { global $user; - // Get languages grouped by status and select only the enabled ones. - $languages = language_list('enabled'); - $languages = $languages[1]; + // Get the enabled languages only. + $languages = language_list(TRUE); if (!isset($provider)) { $providers = language_negotiation_info(); @@ -454,17 +453,8 @@ function language_fallback_get_candidates($type = LANGUAGE_TYPE_CONTENT) { $fallback_candidates = &drupal_static(__FUNCTION__); if (!isset($fallback_candidates)) { - $fallback_candidates = array(); - - // Get languages ordered by weight. - // Use array keys to avoid duplicated entries. - foreach (language_list('weight') as $languages) { - foreach ($languages as $language) { - $fallback_candidates[$language->langcode] = NULL; - } - } - - $fallback_candidates = array_keys($fallback_candidates); + // Get languages ordered by weight, add LANGUAGE_NONE as the last one. + $fallback_candidates = array_keys(language_list()); $fallback_candidates[] = LANGUAGE_NONE; // Let other modules hook in and add/change candidates. diff --git a/core/includes/locale.inc b/core/includes/locale.inc index a73ccc25a5b..e2a79b62385 100644 --- a/core/includes/locale.inc +++ b/core/includes/locale.inc @@ -349,14 +349,16 @@ function locale_language_url_fallback($language = NULL, $language_type = LANGUAG } /** - * Return the URL language switcher block. Translation links may be provided by - * other modules. + * Return links for the URL language switcher block. + * + * Translation links may be provided by other modules. */ function locale_language_switcher_url($type, $path) { - $languages = language_list('enabled'); + // Get the enabled languages only. + $languages = language_list(TRUE); $links = array(); - foreach ($languages[1] as $language) { + foreach ($languages as $language) { $links[$language->langcode] = array( 'href' => $path, 'title' => $language->name, @@ -377,13 +379,14 @@ function locale_language_switcher_session($type, $path) { $param = variable_get('locale_language_negotiation_session_param', 'language'); $language_query = isset($_SESSION[$param]) ? $_SESSION[$param] : $GLOBALS[$type]->langcode; - $languages = language_list('enabled'); + // Get the enabled languages only. + $languages = language_list(TRUE); $links = array(); $query = $_GET; unset($query['q']); - foreach ($languages[1] as $language) { + foreach ($languages as $language) { $langcode = $language->langcode; $links[$langcode] = array( 'href' => $path, @@ -413,8 +416,9 @@ function locale_language_url_rewrite_url(&$path, &$options) { $languages = &$drupal_static_fast['languages']; if (!isset($languages)) { - $languages = language_list('enabled'); - $languages = array_flip(array_keys($languages[1])); + // Get the enabled languages only. + $languages = language_list(TRUE); + $languages = array_flip(array_keys($languages)); } // Language can be passed as an option, or we go for current URL language. @@ -488,8 +492,8 @@ function locale_language_url_rewrite_session(&$path, &$options) { if (!isset($query_rewrite)) { global $user; if (!$user->uid) { - $languages = language_list('enabled'); - $languages = $languages[1]; + // Get the enabled languages only. + $languages = language_list(TRUE); $query_param = check_plain(variable_get('locale_language_negotiation_session_param', 'language')); $query_value = isset($_GET[$query_param]) ? check_plain($_GET[$query_param]) : NULL; $query_rewrite = isset($languages[$query_value]) && language_negotiation_get_any(LOCALE_LANGUAGE_NEGOTIATION_SESSION); diff --git a/core/modules/dashboard/dashboard-rtl.css b/core/modules/dashboard/dashboard-rtl.css index cfccfa0310a..8d3d0edd05c 100644 --- a/core/modules/dashboard/dashboard-rtl.css +++ b/core/modules/dashboard/dashboard-rtl.css @@ -1,3 +1,8 @@ +/** + * @file + * Right-to-left specific stylesheet for the Dashboard module. + */ + #dashboard div.dashboard-region { float: right; } diff --git a/core/modules/dashboard/dashboard.api.php b/core/modules/dashboard/dashboard.api.php index 00bfde5a30a..623dd30abe3 100644 --- a/core/modules/dashboard/dashboard.api.php +++ b/core/modules/dashboard/dashboard.api.php @@ -11,7 +11,7 @@ */ /** - * Adds regions to the dashboard. + * Add regions to the dashboard. * * @return * An array whose keys are the names of the dashboard regions and whose diff --git a/core/modules/dashboard/dashboard.css b/core/modules/dashboard/dashboard.css index 9996ba9d77d..e94964091cb 100644 --- a/core/modules/dashboard/dashboard.css +++ b/core/modules/dashboard/dashboard.css @@ -1,3 +1,8 @@ +/** + * @file + * Stylesheet for the Dashboard module. + */ + #dashboard div.dashboard-region { float: left; min-height: 1px; diff --git a/core/modules/dashboard/dashboard.js b/core/modules/dashboard/dashboard.js index ebecbf65a44..ca2a3b5dea3 100644 --- a/core/modules/dashboard/dashboard.js +++ b/core/modules/dashboard/dashboard.js @@ -1,7 +1,12 @@ +/** + * @file + * Attaches behaviors for the Dashboard module. + */ + (function ($) { /** - * Implementation of Drupal.behaviors for dashboard. + * Implements Drupal.behaviors for the Dashboard module. */ Drupal.behaviors.dashboard = { attach: function (context, settings) { @@ -39,7 +44,7 @@ Drupal.behaviors.dashboard = { }, /** - * Enter "customize" mode by displaying disabled blocks. + * Enters "customize" mode by displaying disabled blocks. */ enterCustomizeMode: function () { $('#dashboard').addClass('customize-mode customize-inactive'); @@ -51,7 +56,7 @@ Drupal.behaviors.dashboard = { }, /** - * Exit "customize" mode by simply forcing a page refresh. + * Exits "customize" mode by simply forcing a page refresh. */ exitCustomizeMode: function () { $('#dashboard').removeClass('customize-mode customize-inactive'); @@ -60,7 +65,7 @@ Drupal.behaviors.dashboard = { }, /** - * Helper for enterCustomizeMode; sets up drag-and-drop and close button. + * Sets up the drag-and-drop behavior and the 'close' button. */ setupDrawer: function () { $('div.customize .canvas-content input').click(Drupal.behaviors.dashboard.exitCustomizeMode); @@ -84,7 +89,7 @@ Drupal.behaviors.dashboard = { }, /** - * While dragging, make the block appear as a disabled block + * Makes the block appear as a disabled block while dragging. * * This function is called on the jQuery UI Sortable "start" event. * @@ -104,8 +109,7 @@ Drupal.behaviors.dashboard = { }, /** - * While dragging, adapt block's width to the width of the region it is moved - * into. + * Adapts block's width to the region it is moved into while dragging. * * This function is called on the jQuery UI Sortable "over" event. * @@ -127,8 +131,7 @@ Drupal.behaviors.dashboard = { }, /** - * While dragging, adapt block's position to stay connected with the position - * of the mouse pointer. + * Adapts a block's position to stay connected with the mouse pointer. * * This function is called on the jQuery UI Sortable "sort" event. * @@ -146,7 +149,7 @@ Drupal.behaviors.dashboard = { }, /** - * Send block order to the server, and expand previously disabled blocks. + * Sends block order to the server, and expands previously disabled blocks. * * This function is called on the jQuery UI Sortable "update" event. * @@ -198,8 +201,10 @@ Drupal.behaviors.dashboard = { }, /** - * Return the current order of the blocks in each of the sortable regions, - * in query string format. + * Returns the current order of the blocks in each of the sortable regions. + * + * @return + * The current order of the blocks, in query string format. */ getOrder: function () { var order = []; diff --git a/core/modules/dashboard/dashboard.module b/core/modules/dashboard/dashboard.module index 115bc8fafa6..1891db59ea4 100644 --- a/core/modules/dashboard/dashboard.module +++ b/core/modules/dashboard/dashboard.module @@ -1,5 +1,10 @@ assertResponse(404, t('Language no longer found.')); // Make sure the "language_count" variable has been updated correctly. drupal_static_reset('language_list'); - $enabled = language_list('enabled'); - $this->assertEqual(variable_get('language_count', 1), count($enabled[1]), t('Language count is correct.')); + $enabled_languages = language_list(TRUE); + $this->assertEqual(variable_get('language_count', 1), count($enabled_languages), t('Language count is correct.')); // Delete a disabled language. // Disable an enabled language. $edit = array( @@ -133,7 +133,7 @@ class LanguageListTest extends DrupalWebTestCase { $this->assertNoFieldChecked('edit-languages-fr-enabled', t('French language disabled.')); // Get the count of enabled languages. drupal_static_reset('language_list'); - $enabled = language_list('enabled'); + $enabled_languages = language_list(TRUE); // Delete the disabled language. $this->drupalPost('admin/config/regional/language/delete/fr', array(), t('Delete')); // We need raw here because %language and %langcode will add HTML. @@ -144,7 +144,7 @@ class LanguageListTest extends DrupalWebTestCase { $this->drupalGet('admin/config/regional/language/delete/fr'); $this->assertResponse(404, t('Language no longer found.')); // Make sure the "language_count" variable has not changed. - $this->assertEqual(variable_get('language_count', 1), count($enabled[1]), t('Language count is correct.')); + $this->assertEqual(variable_get('language_count', 1), count($enabled_languages), t('Language count is correct.')); // Ensure we can delete the English language. Right now English is the only // language so we must add a new language and make it the default before diff --git a/core/modules/locale/locale.admin.inc b/core/modules/locale/locale.admin.inc index 26165f87465..c0a91370e3d 100644 --- a/core/modules/locale/locale.admin.inc +++ b/core/modules/locale/locale.admin.inc @@ -256,10 +256,11 @@ function locale_language_providers_url_form($form, &$form_state) { ), ); - $languages = language_list('enabled'); + // Get the enabled languages only. + $languages = language_list(TRUE); $prefixes = locale_language_negotiation_url_prefixes(); $domains = locale_language_negotiation_url_domains(); - foreach ($languages[1] as $langcode => $language) { + foreach ($languages as $langcode => $language) { $form['prefix'][$langcode] = array( '#type' => 'textfield', '#title' => t('%language (%langcode) path prefix', array('%language' => $language->name, '%langcode' => $language->langcode)), @@ -292,40 +293,41 @@ function locale_language_providers_url_form($form, &$form_state) { * the prefix and domain are only blank for the default. */ function locale_language_providers_url_form_validate($form, &$form_state) { - $languages = locale_language_list(); + // Get the enabled languages only. + $languages = language_list(TRUE); $default = language_default(); // Count repeated values for uniqueness check. $count = array_count_values($form_state['values']['prefix']); - foreach ($languages as $langcode => $name) { + foreach ($languages as $langcode => $language) { $value = $form_state['values']['prefix'][$langcode]; if ($value === '') { - if ($default->langcode != $langcode && $form_state['values']['locale_language_negotiation_url_part'] == LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX) { + if (!$language->default && $form_state['values']['locale_language_negotiation_url_part'] == LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX) { // Validation error if the prefix is blank for a non-default language, and value is for selected negotiation type. form_error($form['prefix'][$langcode], t('The prefix may only be left blank for the default language.')); } } else if (isset($count[$value]) && $count[$value] > 1) { // Validation error if there are two languages with the same domain/prefix. - form_error($form['prefix'][$langcode], t('The prefix for %language, %value, is not unique.', array( '%language' => $name, '%value' => $value ))); + form_error($form['prefix'][$langcode], t('The prefix for %language, %value, is not unique.', array('%language' => $language->name, '%value' => $value))); } } // Count repeated values for uniqueness check. $count = array_count_values($form_state['values']['domain']); - foreach ($languages as $langcode => $name) { + foreach ($languages as $langcode => $language) { $value = $form_state['values']['domain'][$langcode]; if ($value === '') { - if ($default->langcode != $langcode && $form_state['values']['locale_language_negotiation_url_part'] == LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN) { + if (!$language->default && $form_state['values']['locale_language_negotiation_url_part'] == LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN) { // Validation error if the domain is blank for a non-default language, and value is for selected negotiation type. form_error($form['domain'][$langcode], t('The domain may only be left blank for the default language.')); } } else if (isset($count[$value]) && $count[$value] > 1) { // Validation error if there are two languages with the same domain/domain. - form_error($form['domain'][$langcode], t('The domain for %language, %value, is not unique.', array( '%language' => $name, '%value' => $value ))); + form_error($form['domain'][$langcode], t('The domain for %language, %value, is not unique.', array('%language' => $language->name, '%value' => $value))); } } } @@ -405,12 +407,12 @@ function locale_date_format_language_overview_page() { array('data' => t('Operations'), 'colspan' => '2'), ); - // Get list of languages. - $languages = locale_language_list(); + // Get the enabled languages only. + $languages = language_list(TRUE); - foreach ($languages as $langcode => $info) { + foreach ($languages as $langcode => $language) { $row = array(); - $row[] = $languages[$langcode]; + $row[] = $language->name; $row[] = l(t('edit'), 'admin/config/regional/date-time/locale/' . $langcode . '/edit'); $row[] = l(t('reset'), 'admin/config/regional/date-time/locale/' . $langcode . '/reset'); $rows[] = $row; @@ -423,14 +425,11 @@ function locale_date_format_language_overview_page() { * Provide date localization configuration options to users. */ function locale_date_format_form($form, &$form_state, $langcode) { - $languages = locale_language_list(); - $language_name = $languages[$langcode]; - // Display the current language name. $form['language'] = array( '#type' => 'item', '#title' => t('Language'), - '#markup' => check_plain($language_name), + '#markup' => language_load($langcode)->name, '#weight' => -10, ); $form['langcode'] = array( @@ -509,9 +508,8 @@ function locale_date_format_form_submit($form, &$form_state) { */ function locale_date_format_reset_form($form, &$form_state, $langcode) { $form['langcode'] = array('#type' => 'value', '#value' => $langcode); - $languages = language_list(); return confirm_form($form, - t('Are you sure you want to reset the date formats for %language to the global defaults?', array('%language' => $languages[$langcode]->name)), + t('Are you sure you want to reset the date formats for %language to the global defaults?', array('%language' => language_load($langcode)->name)), 'admin/config/regional/date-time/locale', t('Resetting will remove all localized date formats for this language. This action cannot be undone.'), t('Reset'), t('Cancel')); diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc index 7982a980346..a4982e13e1a 100644 --- a/core/modules/locale/locale.bulk.inc +++ b/core/modules/locale/locale.bulk.inc @@ -11,24 +11,32 @@ include_once DRUPAL_ROOT . '/core/includes/gettext.inc'; * User interface for the translation import screen. */ function locale_translate_import_form($form, &$form_state) { - // Get all languages, except English drupal_static_reset('language_list'); - $names = locale_language_list('name'); - if (!locale_translate_english()) { - unset($names['en']); + $languages = language_list(TRUE); + + // Initialize a language list to the ones available, including English if we + // are to translate Drupal to English as well. + $existing_languages = array(); + foreach ($languages as $langcode => $language) { + if ($langcode != 'en' || locale_translate_english()) { + $existing_languages[$langcode] = $language->name; + } } + // If we have no languages available, present the list of predefined languages + // only. If we do have already added languages, set up two option groups with + // the list of existing and then predefined languages. form_load_include($form_state, 'inc', 'language', 'language.admin'); - if (!count($names)) { - $languages = language_admin_predefined_list(); - $default = key($languages); + if (empty($existing_languages)) { + $language_options = language_admin_predefined_list(); + $default = key($language_options); } else { - $languages = array( - t('Already added languages') => $names, + $default = key($existing_languages); + $language_options = array( + t('Already added languages') => $existing_languages, t('Languages not yet added') => language_admin_predefined_list() ); - $default = key($names); } $form['import'] = array('#type' => 'fieldset', @@ -41,7 +49,7 @@ function locale_translate_import_form($form, &$form_state) { ); $form['import']['langcode'] = array('#type' => 'select', '#title' => t('Import into'), - '#options' => $languages, + '#options' => $language_options, '#default_value' => $default, '#description' => t('Choose the language you want to add strings into. If you choose a language which is not yet set up, it will be added.'), ); @@ -101,16 +109,20 @@ function locale_translate_import_form_submit($form, &$form_state) { * User interface for the translation export screen. */ function locale_translate_export_screen() { - // Get all languages, except English + // Get all enabled languages, except English, if we should not translate that. drupal_static_reset('language_list'); - $names = locale_language_list('name'); - if (!locale_translate_english()) { - unset($names['en']); + $languages = language_list(TRUE); + $language_options = array(); + foreach ($languages as $langcode => $language) { + if ($langcode != 'en' || locale_translate_english()) { + $language_options[$langcode] = $language->name; + } } + $output = ''; // Offer translation export if any language is set up. - if (count($names)) { - $elements = drupal_get_form('locale_translate_export_po_form', $names); + if (!empty($language_options)) { + $elements = drupal_get_form('locale_translate_export_po_form', $language_options); $output = drupal_render($elements); } $elements = drupal_get_form('locale_translate_export_pot_form'); diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 9330df1134e..6b189889b50 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -219,8 +219,8 @@ function locale_permission() { */ function locale_language_selector_form($user) { global $language; - $languages = language_list('enabled'); - $languages = $languages[1]; + // Get list of enabled languages only. + $languages = language_list(TRUE); // If the user is being created, we set the user language to the page language. $user_preferred_language = $user->uid ? user_preferred_language($user) : $language; @@ -296,11 +296,16 @@ function locale_form_alter(&$form, &$form_state, $form_id) { */ function locale_form_node_form_alter(&$form, &$form_state) { if (isset($form['#node']->type) && locale_multilingual_node_type($form['#node']->type)) { + $languages = language_list(TRUE); + $language_options = array(LANGUAGE_NONE => t('Language neutral')); + foreach ($languages as $langcode => $language) { + $language_options[$langcode] = $language->name; + } $form['language'] = array( '#type' => 'select', '#title' => t('Language'), '#default_value' => (isset($form['#node']->language) ? $form['#node']->language : ''), - '#options' => array(LANGUAGE_NONE => t('Language neutral')) + locale_language_list('name'), + '#options' => $language_options, ); } // Node type without language selector: assign the default for new nodes @@ -764,37 +769,12 @@ function locale_get_plural($count, $langcode = NULL) { /** - * Returns a language name + * Returns a language name. */ -function locale_language_name($lang) { - $list = &drupal_static(__FUNCTION__); - if (!isset($list)) { - $list = locale_language_list(); - } - return ($lang && isset($list[$lang])) ? $list[$lang] : t('All'); -} - -/** - * Returns array of language names - * - * @param $field - * Name of language object field. - * @param $all - * Boolean to return all languages or only enabled ones - */ -function locale_language_list($field = 'name', $all = FALSE) { - if ($all) { - $languages = language_list(); - } - else { - $languages = language_list('enabled'); - $languages = $languages[1]; - } - $list = array(); - foreach ($languages as $language) { - $list[$language->langcode] = $language->$field; - } - return $list; +function locale_language_name($langcode) { + // Consider enabled languages only. + $languages = language_list(TRUE); + return ($langcode && isset($languages[$langcode])) ? $languages[$langcode]->name : t('All'); } /** diff --git a/core/modules/locale/locale.pages.inc b/core/modules/locale/locale.pages.inc index ef843ec1fab..e41bae59d4b 100644 --- a/core/modules/locale/locale.pages.inc +++ b/core/modules/locale/locale.pages.inc @@ -152,9 +152,12 @@ function locale_translation_filters() { // Get all languages, except English drupal_static_reset('language_list'); - $languages = locale_language_list('name'); - if (!locale_translate_english()) { - unset($languages['en']); + $languages = language_list(TRUE); + $language_options = array(); + foreach ($languages as $langcode => $language) { + if ($langcode != 'en' || locale_translate_english()) { + $language_options[$langcode] = $language->name; + } } $filters['string'] = array( @@ -164,7 +167,7 @@ function locale_translation_filters() { $filters['language'] = array( 'title' => t('Language'), - 'options' => array_merge(array('all' => t('All languages'), LANGUAGE_SYSTEM => t('System (English)')), $languages), + 'options' => array_merge(array('all' => t('All languages'), LANGUAGE_SYSTEM => t('System (English)')), $language_options), ); $filters['translation'] = array( diff --git a/core/modules/locale/locale.test b/core/modules/locale/locale.test index fae4688b272..f102d4bdf5a 100644 --- a/core/modules/locale/locale.test +++ b/core/modules/locale/locale.test @@ -2032,8 +2032,8 @@ class LocaleUILanguageNegotiationTest extends DrupalWebTestCase { // is for some reason not found when doing translate search. This might // be some bug. drupal_static_reset('language_list'); - $languages = language_list('enabled'); - variable_set('language_default', $languages[1]['vi']); + $languages = language_list(TRUE); + variable_set('language_default', $languages['vi']); // First visit this page to make sure our target string is searchable. $this->drupalGet('admin/config'); // Now the t()'ed string is in db so switch the language back to default. diff --git a/core/modules/node/node.admin.inc b/core/modules/node/node.admin.inc index d8caa94f610..b5b2075cdc3 100644 --- a/core/modules/node/node.admin.inc +++ b/core/modules/node/node.admin.inc @@ -106,14 +106,18 @@ function node_filters() { ) + node_type_get_names(), ); - // Language filter if there is a list of languages - if ($languages = module_invoke('locale', 'language_list')) { - $languages = array(LANGUAGE_NONE => t('Language neutral')) + $languages; + // Language filter if the site is multilingual. + if (language_multilingual()) { + $languages = language_list(TRUE); + $language_options = array(LANGUAGE_NONE => t('Language neutral')); + foreach ($languages as $langcode => $language) { + $language_options[$langcode] = $language->name; + } $filters['language'] = array( 'title' => t('language'), 'options' => array( '[any]' => t('any'), - ) + $languages, + ) + $language_options, ); } return $filters; diff --git a/core/modules/openid/openid.module b/core/modules/openid/openid.module index 1180114481e..edd73d39cc1 100644 --- a/core/modules/openid/openid.module +++ b/core/modules/openid/openid.module @@ -258,8 +258,7 @@ function openid_form_user_register_form_alter(&$form, &$form_state) { $candidate_languages[] = $parts[0] . '-' . $parts[2]; $candidate_languages[] = $parts[0] . '-' . $parts[1] . '-' . $parts[2]; } - $all_languages = language_list('enabled'); - $enabled_languages = $all_languages[1]; + $enabled_languages = language_list(TRUE); // Iterate over the generated permutations starting with the longest (most // specific) strings. foreach (array_reverse($candidate_languages) as $candidate_language) { diff --git a/core/modules/path/path.admin.inc b/core/modules/path/path.admin.inc index 0ad3ab56ff1..4bca34ad478 100644 --- a/core/modules/path/path.admin.inc +++ b/core/modules/path/path.admin.inc @@ -132,10 +132,16 @@ function path_admin_form($form, &$form_state, $path = array('source' => '', 'ali // A hidden value unless locale module is enabled. if (module_exists('locale')) { + $languages = language_list(TRUE); + $language_options = array(LANGUAGE_NONE => t('All languages')); + foreach ($languages as $langcode => $language) { + $language_options[$langcode] = $language->name; + } + $form['langcode'] = array( '#type' => 'select', '#title' => t('Language'), - '#options' => array(LANGUAGE_NONE => t('All languages')) + locale_language_list('name'), + '#options' => $language_options, '#default_value' => $path['langcode'], '#weight' => -10, '#description' => t('A path alias set for a specific language will always be used when displaying this page in that language, and takes precedence over path aliases set for All languages.'), diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 5fb47add426..a5bfd1023d0 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -3908,10 +3908,7 @@ function system_date_format_save($date_format, $dfid = 0) { } // Retrieve an array of language objects for enabled languages. - $languages = language_list('enabled'); - // This list is keyed off the value of $language->enabled; we want the ones - // that are enabled (value of 1). - $languages = $languages[1]; + $languages = language_list(TRUE); $locale_format = array(); $locale_format['type'] = $date_format['type']; diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 338638f6c8b..606abfc017e 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -1048,9 +1048,9 @@ function taxonomy_get_tree($vid, $parent = 0, $max_depth = NULL, $load_entities break; } $term = $load_entities ? $term_entities[$child] : $terms[$vid][$child]; - if (count($parents[$vid][$term->tid]) > 1) { - // We have a term with multi parents here. Clone the term, - // so that the depth attribute remains correct. + if (isset($parents[$vid][$term->tid])) { + // Clone the term so that the depth attribute remains correct + // in the event of multiple parents. $term = clone $term; } $term->depth = $depth; diff --git a/core/modules/taxonomy/taxonomy.test b/core/modules/taxonomy/taxonomy.test index a7f7bd9d6be..aa3c20993a6 100644 --- a/core/modules/taxonomy/taxonomy.test +++ b/core/modules/taxonomy/taxonomy.test @@ -416,6 +416,60 @@ class TaxonomyTermUnitTest extends TaxonomyWebTestCase { // Delete an invalid term. Should not throw any notices. taxonomy_term_delete(42); } + + /** + * Test a taxonomy with terms that have multiple parents of different depths. + */ + function testTaxonomyVocabularyTree() { + // Create a new vocabulary with 6 terms. + $vocabulary = $this->createVocabulary(); + $term = array(); + for ($i = 0; $i < 6; $i++) { + $term[$i] = $this->createTerm($vocabulary); + } + + // $term[2] is a child of 1 and 5. + $term[2]->parent = array($term[1]->tid, $term[5]->tid); + taxonomy_term_save($term[2]); + // $term[3] is a child of 2. + $term[3]->parent = array($term[2]->tid); + taxonomy_term_save($term[3]); + // $term[5] is a child of 4. + $term[5]->parent = array($term[4]->tid); + taxonomy_term_save($term[5]); + + /** + * Expected tree: + * term[0] | depth: 0 + * term[1] | depth: 0 + * -- term[2] | depth: 1 + * ---- term[3] | depth: 2 + * term[4] | depth: 0 + * -- term[5] | depth: 1 + * ---- term[2] | depth: 2 + * ------ term[3] | depth: 3 + */ + + // Count $term[1] parents with $max_depth = 1. + $tree = taxonomy_get_tree($vocabulary->vid, $term[1]->tid, 1); + $this->assertEqual(1, count($tree), 'We have one parent with depth 1.'); + + // Count all vocabulary tree elements. + $tree = taxonomy_get_tree($vocabulary->vid); + $this->assertEqual(8, count($tree), 'We have all vocabulary tree elements.'); + + // Count elements in every tree depth. + foreach($tree as $element) { + if (!isset($depth_count[$element->depth])) { + $depth_count[$element->depth] = 0; + } + $depth_count[$element->depth]++; + } + $this->assertEqual(3, $depth_count[0], 'Three elements in taxonomy tree depth 0.'); + $this->assertEqual(2, $depth_count[1], 'Two elements in taxonomy tree depth 1.'); + $this->assertEqual(2, $depth_count[2], 'Two elements in taxonomy tree depth 2.'); + $this->assertEqual(1, $depth_count[3], 'One element in taxonomy tree depth 3.'); + } } /** diff --git a/core/modules/translation/translation.module b/core/modules/translation/translation.module index 5fbdf01b0c6..e121f041320 100644 --- a/core/modules/translation/translation.module +++ b/core/modules/translation/translation.module @@ -125,20 +125,25 @@ function translation_form_node_type_form_alter(&$form, &$form_state) { function translation_form_node_form_alter(&$form, &$form_state) { if (translation_supported_type($form['#node']->type)) { $node = $form['#node']; - $languages = language_list('enabled'); - $disabled_languages = isset($languages[0]) ? $languages[0] : FALSE; - $translator_widget = $disabled_languages && user_access('translate content'); + + // Build two lists with the disabled and enabled languages. + $languages = language_list(); + $grouped_languages = array(); + foreach ($languages as $langcode => $language) { + $grouped_languages[(int) $language->enabled][$langcode] = $language; + } + + $translator_widget = !empty($grouped_languages[0]) && user_access('translate content'); $groups = array(t('Disabled'), t('Enabled')); // Allow translators to enter content in disabled languages. Translators // might need to distinguish between enabled and disabled languages, hence // we divide them in two option groups. if ($translator_widget) { $options = array($groups[1] => array(LANGUAGE_NONE => t('Language neutral'))); - $language_list = locale_language_list('name', TRUE); foreach (array(1, 0) as $status) { $group = $groups[$status]; - foreach ($languages[$status] as $langcode => $language) { - $options[$group][$langcode] = $language_list[$langcode]; + foreach ($grouped_languages[$status] as $langcode => $language) { + $options[$group][$langcode] = $language->name; } } $form['language']['#options'] = $options; @@ -208,8 +213,7 @@ function translation_node_view($node, $view_mode) { // If the site has no translations or is not multilingual we have no content // translation links to display. if (isset($node->tnid) && language_multilingual() && $translations = translation_node_get_translations($node->tnid)) { - $languages = language_list('enabled'); - $languages = $languages[1]; + $languages = language_list(TRUE); // There might be a language provider enabled defining custom language // switch links which need to be taken into account while generating the