Commit 910535c9 authored by Crell's avatar Crell
Browse files

Merge branch '8.x' into 1400748-namespaces

parents d0dd7614 4b928417
......@@ -2652,53 +2652,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.
*/
function language_list($field = 'langcode') {
* An associative array of languages, keyed by the language code, ordered by
* weight ascending and name ascending.
*/
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'];
}
/**
......@@ -3204,29 +3196,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
......
......@@ -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.
......
......@@ -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);
......
/**
* @file
* Right-to-left specific stylesheet for the Dashboard module.
*/
#dashboard div.dashboard-region {
float: right;
}
......
......@@ -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
......
/**
* @file
* Stylesheet for the Dashboard module.
*/
#dashboard div.dashboard-region {
float: left;
min-height: 1px;
......
/**
* @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 = [];
......
<?php
/**
* @file
* Provides a dashboard page in the administrative interface.
*/
/**
* Implements hook_help().
*/
......@@ -263,10 +268,12 @@ function dashboard_forms() {
}
/**
* Dashboard page callback.
* Page callback: Displays the dashboard.
*
* @param $launch_customize
* Whether to launch in customization mode right away. TRUE or FALSE.
*
* @see dashboard_menu()
*/
function dashboard_admin($launch_customize = FALSE) {
$js_settings = array(
......@@ -298,11 +305,12 @@ function dashboard_admin($launch_customize = FALSE) {
}
/**
* Menu page callback: builds the page for administering dashboard blocks.
* Page callback: Builds the page for administering dashboard blocks.
*
* This page reuses the Block module's administration form but limits editing
* to blocks that are available to appear on the dashboard.
*
* @see dashboard_menu()
* @see block_admin_display()
* @see block_admin_display_form()
* @see dashboard_form_dashboard_admin_display_form_alter()
......@@ -454,7 +462,7 @@ function dashboard_is_visible() {
}
/**
* Return an array of dashboard region descriptions, keyed by region name.
* Returns an array of dashboard region descriptions, keyed by region name.
*/
function dashboard_region_descriptions() {
$regions = module_invoke_all('dashboard_regions');
......@@ -463,7 +471,7 @@ function dashboard_region_descriptions() {
}
/**
* Return an array of dashboard region names.
* Returns an array of dashboard region names.
*/
function dashboard_regions() {
$regions = &drupal_static(__FUNCTION__);
......@@ -485,7 +493,9 @@ function dashboard_dashboard_regions() {
}
/**
* Ajax callback to show disabled blocks in the dashboard customization mode.
* Ajax callback: Shows disabled blocks in the dashboard customization mode.
*
* @see dashboard_menu()
*/
function dashboard_show_disabled() {
global $theme_key;
......@@ -506,12 +516,14 @@ function dashboard_show_disabled() {
}
/**
* Ajax callback to display the rendered contents of a specific block.
* Ajax callback: Displays the rendered contents of a specific block.
*
* @param $module
* The block's module name.
* @param $delta
* The block's delta.
*
* @see dashboard_menu()
*/
function dashboard_show_block_content($module, $delta) {
drupal_theme_initialize();
......@@ -533,7 +545,7 @@ function dashboard_show_block_content($module, $delta) {
}
/**
* Set the new weight of each region according to the drag-and-drop order.
* Sets the new weight of each region according to the drag-and-drop order.
*/
function dashboard_update() {
drupal_theme_initialize();
......@@ -630,7 +642,7 @@ function theme_dashboard_region($variables) {
}
/**
* Returns HTML for a set of disabled blocks, for display in dashboard customization mode.
* Returns HTML for disabled blocks, for use in dashboard customization mode.
*
* @param $variables
* An associative array containing:
......@@ -652,7 +664,7 @@ function theme_dashboard_disabled_blocks($variables) {
}
/**
* Returns HTML for a disabled block, for display in dashboard customization mode.
* Returns HTML for a disabled block, for use in dashboard customization mode.
*
* @param $variables
* An associative array containing:
......
......@@ -5,6 +5,9 @@
* Tests for dashboard.module.
*/
/**
* Tests the Dashboard module blocks.
*/
class DashboardBlocksTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
......@@ -33,7 +36,7 @@ class DashboardBlocksTestCase extends DrupalWebTestCase {
}
/**
* Test adding a block to the dashboard and checking access to it.
* Tests adding a block to the dashboard and checking access to it.
*/
function testDashboardAccess() {
// Add a new custom block to a dashboard region.
......@@ -58,7 +61,7 @@ class DashboardBlocksTestCase extends DrupalWebTestCase {
}
/**
* Test that dashboard regions are displayed or hidden properly.
* Tests that dashboard regions are displayed or hidden properly.
*/
function testDashboardRegions() {
$dashboard_regions = dashboard_region_descriptions();
......@@ -80,8 +83,7 @@ class DashboardBlocksTestCase extends DrupalWebTestCase {
}
/**
* Test that the dashboard module can be disabled and enabled again,
* retaining its blocks.
* Tests that the dashboard module can be re-enabled, retaining its blocks.
*/
function testDisableEnable() {
// Add a new custom block to a dashboard region.
......@@ -113,8 +115,7 @@ class DashboardBlocksTestCase extends DrupalWebTestCase {
}
/**
* Test that defining a block with ['properties']['administrative'] = TRUE
* adds it as an available block for the dashboard.
* Tests that administrative blocks are available for the dashboard.
*/
function testBlockAvailability() {
// Test "Recent comments", which should be available (defined as
......
......@@ -122,8 +122,8 @@ class LanguageListTest extends DrupalWebTestCase {
$this->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
......
......@@ -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'));
......
......@@ -11,24 +11,32 @@
* User interface for the translation import screen.
*/
function locale_translate_import_form($form, &$form_state) {