diff --git a/core/modules/language/language.module b/core/modules/language/language.module index d9bd7d4..da66014 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -215,6 +215,8 @@ function language_process_language_select($element) { if (!isset($element['#options'])) { $element['#options'] = array(); foreach (language_list($element['#languages']) as $langcode => $language) { + // @todo: http://drupal.org/node/1739928#comment-6471438 + // Is this flipped? If it's locked, put it in t() so it can be translated? $element['#options'][$langcode] = $language->locked ? t('- @name -', array('@name' => $language->name)) : $language->name; } } @@ -320,7 +322,7 @@ function language_configuration_element_submit(&$form, &$form_state) { * - langcode: the language code. * - language_hidden: if the language element should be hidden or not. */ -function language_save_default_configuration($entity_type, $bundle, $values = array()) { +function language_save_default_configuration($entity_type, $bundle, $values = array()) { config('language.settings')->set(language_get_default_configuration_settings_path($entity_type, $bundle), array('langcode' => $values['langcode'], 'language_hidden' => $values['language_hidden']))->save(); } @@ -337,6 +339,7 @@ function language_save_default_configuration($entity_type, $bundle, $values = a * - language_hidden: if the language element is hidden or not. */ function language_get_default_configuration($entity_type, $bundle) { + // @todo: http://drupal.org/node/1783346 for unresolved CMI issue. $configuration = config('language.settings')->get(language_get_default_configuration_settings_path($entity_type, $bundle)); if (is_null($configuration)) { $configuration = array(); @@ -371,6 +374,10 @@ function language_clear_default_configuration($entity_type, $bundle) { * The root name of the variables. */ function language_get_default_configuration_settings_path($entity_type, $bundle) { + // @todo: http://drupal.org/node/1739928#comment-6471438 + // Since these values are more or less coming in directly from + // $form_state['values'], should there be some sanitization here to ensure + // people aren't putting nonsense like "../../../../" in there? return 'language.default_configuration.' . $entity_type . '.' . $bundle; } @@ -383,7 +390,6 @@ function language_get_default_configuration_settings_path($entity_type, $bundle) * The bundle name. * @return string * The language code. - * */ function language_get_default_langcode($entity_type, $bundle) { $configuration = language_get_default_configuration($entity_type, $bundle); @@ -417,8 +423,8 @@ function language_get_default_langcode($entity_type, $bundle) { return $default_value; } - // If we still not have a default value, just return the value stored in the - // configuration, it has to be an actual language code. + // If we still do not have a default value, just return the value stored in + // the configuration; it has to be an actual language code. return $configuration['langcode']; } diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationElementTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationElementTest.php index 91ec9ce..3747c86 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationElementTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationElementTest.php @@ -30,12 +30,16 @@ class LanguageConfigurationElementTest extends WebTestBase { ); } + /** + * Tests the language settings have been saved. + */ public function testLanguageConfigurationElement() { $this->drupalGet('language-tests/language_configuration_element'); $edit['lang_configuration[langcode]'] = 'current_interface'; $edit['lang_configuration[language_hidden]'] = TRUE; $this->drupalPost(NULL, $edit, 'Save'); $lang_conf = language_get_default_configuration('some_custom_type', 'some_bundle'); + // Check that the settings have been saved. $this->assertEqual($lang_conf['langcode'], 'current_interface'); $this->assertTrue($lang_conf['language_hidden']); @@ -49,6 +53,7 @@ class LanguageConfigurationElementTest extends WebTestBase { $edit['lang_configuration[language_hidden]'] = FALSE; $this->drupalPost(NULL, $edit, 'Save'); $lang_conf = language_get_default_configuration('some_custom_type', 'some_bundle'); + // Check that the settings have been saved. $this->assertEqual($lang_conf['langcode'], 'authors_default'); $this->assertFalse($lang_conf['language_hidden']); @@ -69,6 +74,7 @@ class LanguageConfigurationElementTest extends WebTestBase { )); language_save($language); } + // Fixed language. language_save_default_configuration('custom_type', 'custom_bundle', array('langcode' => 'bb', 'language_hidden' => FALSE)); $langcode = language_get_default_langcode('custom_type', 'custom_bundle'); diff --git a/core/modules/node/content_types.inc b/core/modules/node/content_types.inc index b5dc922..bc8e84a 100644 --- a/core/modules/node/content_types.inc +++ b/core/modules/node/content_types.inc @@ -192,6 +192,10 @@ function node_type_form($form, &$form_state, $type = NULL) { '#collapsed' => TRUE, '#group' => 'additional_settings', ); + + // @todo: http://drupal.org/node/1739928#comment-6471438 + // In taxonomy module, this was wrapped in an if (module_exists('language')) + // check. Why is it not here? $language_configuration = language_get_default_configuration('node', $type->type); $form['language']['language_configuration'] = array( '#type' => 'language_configuration', diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyLanguageTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyLanguageTest.php index db3ecc8..f61b9e5 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyLanguageTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyLanguageTest.php @@ -45,8 +45,12 @@ class VocabularyLanguageTest extends TaxonomyTestBase { language_save($language); } + /** + * Tests language settings for vocabularies. + */ function testVocabularyLanguage() { $this->drupalGet('admin/structure/taxonomy/add'); + // Check that we have the language selector available. $this->assertField('edit-langcode', t('The language selector field was found on the page')); @@ -71,6 +75,9 @@ class VocabularyLanguageTest extends TaxonomyTestBase { $this->assertOptionSelected('edit-langcode', $edit['langcode'], t('The vocabulary language was correctly selected.')); } + /** + * Tests term language settings for vocabulary terms are saved and updated. + */ function testVocabularyDefaultLanguageForTerms() { // Add a new vocabulary and check that the default language settings are for // the terms are saved. @@ -82,6 +89,7 @@ class VocabularyLanguageTest extends TaxonomyTestBase { ); $machine_name = $edit['machine_name']; $this->drupalPost('admin/structure/taxonomy/add', $edit, t('Save')); + // Check that the vocabulary was actually created. $this->drupalGet('admin/structure/taxonomy/' . $edit['machine_name'] . '/edit'); $this->assertResponse(200, 'The vocabulary has been created.'); @@ -120,7 +128,8 @@ class VocabularyLanguageTest extends TaxonomyTestBase { ); $new_machine_name = $edit['machine_name']; $this->drupalPost('admin/structure/taxonomy/' . $machine_name . '/edit', $edit, t('Save')); - // Check that the the old settings are empty. + + // Check that the old settings are empty. $old_settings = config('language.settings')->get(language_get_default_configuration_settings_path('vocabulary', $machine_name)); $this->assertNull($old_settings, 'The old vocabulary settings were deleted.'); // Check that we have the new settings. diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php index ad7ad89..450cd55 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php @@ -44,6 +44,11 @@ class VocabularyFormController extends EntityFormController { '#title' => t('Description'), '#default_value' => $vocabulary->description, ); + + // $form['langcode'] is not wrapped in an if (module_exists('language')) + // check because the language_select form element works also without the + // language module being installed. + // http://drupal.org/node/1749954 documents the new element. $form['langcode'] = array( '#type' => 'language_select', '#title' => t('Vocabulary language'), @@ -87,7 +92,7 @@ class VocabularyFormController extends EntityFormController { $actions = parent::actions($form, $form_state); array_unshift($actions['delete']['#submit'], array($this, 'submit')); // Add the language configuration submit handler. This is needed because - // the submit buttons has custom submit handlers. + // the submit button has custom submit handlers. if (module_exists('language')) { array_unshift($actions['submit']['#submit'],'language_configuration_element_submit'); array_unshift($actions['submit']['#submit'], array($this, 'languageConfigurationSubmit'));