diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php index dd4c028a6b58faa08c0d0146a24570c2da6a1835..5487e04d0a62c54437a057bbe11b98773feab40d 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigStorageController.php @@ -284,6 +284,9 @@ protected function attachLoad(&$queried_entities, $revision_id = FALSE) { public function create(array $values) { $class = $this->entityInfo['class']; + // Set default language to site default if not provided. + $values += array('langcode' => language_default()->langcode); + $entity = new $class($values, $this->entityType); // Mark this entity as new, so isNew() returns TRUE. This does not check // whether a configuration entity with the same ID (if any) already exists. diff --git a/core/lib/Drupal/Core/Entity/EntityFormController.php b/core/lib/Drupal/Core/Entity/EntityFormController.php index 4a03975c2c509f3dba7f4e46c61aeb92df262b0a..6d2c9fb8ca343b40fcf5ae71663b6b21381ac61d 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormController.php +++ b/core/lib/Drupal/Core/Entity/EntityFormController.php @@ -80,6 +80,15 @@ public function form(array $form, array &$form_state, EntityInterface $entity) { if (!empty($info['fieldable'])) { field_attach_form($entity, $form, $form_state, $this->getFormLangcode($form_state)); } + if (!isset($form['langcode'])) { + // If the form did not specify otherwise, default to keeping the existing + // language of the entity or defaulting to the site default language for + // new entities. + $form['langcode'] = array( + '#type' => 'value', + '#value' => !$entity->isNew() ? $entity->langcode : language_default()->langcode, + ); + } return $form; } diff --git a/core/modules/block/custom_block/config/custom_block.type.basic.yml b/core/modules/block/custom_block/config/custom_block.type.basic.yml index 1b0e2f8dc5341bf92b06675112dd20bace46e673..58e87d757bcdfdd533481da19b98ba0abc0eacb5 100644 --- a/core/modules/block/custom_block/config/custom_block.type.basic.yml +++ b/core/modules/block/custom_block/config/custom_block.type.basic.yml @@ -2,3 +2,4 @@ id: basic label: Basic block revision: '0' description: A basic block contains a title and a body. +langcode: en diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTypeTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTypeTest.php index d94e47638cd96b5d75be8705d05f04cac49eddac..eee184adbb16a45421fbb9fb5ca9b599f26df181 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTypeTest.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockTypeTest.php @@ -64,6 +64,10 @@ public function testCustomBlockTypeCreation() { $this->drupalPost('admin/structure/custom-blocks/add', $edit, t('Save')); $block_type = entity_load('custom_block_type', 'foo'); $this->assertTrue($block_type, 'The new block type has been created.'); + + // Check that the block type was created in site default language. + $default_langcode = language_default()->langcode; + $this->assertEqual($block_type->langcode, $default_langcode); } /** diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php index 490e434fa8295a22443a32b6920fb9fc50c21459..207f20bd001f5325dacb771264d6dab77ac8c407 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php @@ -104,7 +104,7 @@ protected function createTests() { 'cache' => '1', 'admin_label' => t('Test block html id'), ), - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => language_default()->langcode, ); $this->assertIdentical($actual_properties, $expected_properties, 'The block properties are exported correctly.'); diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php index 90ae934d33c1f33d70b6d75dc35ea57a3765b11f..84fbc97b82302a169bb0b51208551b32420370c7 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php @@ -35,13 +35,14 @@ public static function getInfo() { */ function testCRUD() { $manifest_name = 'manifest.config_test.dynamic'; + $default_langcode = language_default()->langcode; // Verify default properties on a newly created empty entity. $empty = entity_create('config_test', array()); $this->assertIdentical($empty->id, NULL); $this->assertTrue($empty->uuid); $this->assertIdentical($empty->label, NULL); $this->assertIdentical($empty->style, NULL); - $this->assertIdentical($empty->langcode, LANGUAGE_NOT_SPECIFIED); + $this->assertIdentical($empty->langcode, $default_langcode); // Verify ConfigEntity properties/methods on the newly created empty entity. $this->assertIdentical($empty->isNew(), TRUE); @@ -55,7 +56,7 @@ function testCRUD() { $this->assertTrue($empty->get('uuid')); $this->assertIdentical($empty->get('label'), NULL); $this->assertIdentical($empty->get('style'), NULL); - $this->assertIdentical($empty->get('langcode'), LANGUAGE_NOT_SPECIFIED); + $this->assertIdentical($empty->get('langcode'), $default_langcode); // Verify Entity properties/methods on the newly created empty entity. $this->assertIdentical($empty->isNewRevision(), FALSE); @@ -97,7 +98,7 @@ function testCRUD() { $this->assertNotEqual($config_test->uuid, $empty->uuid); $this->assertIdentical($config_test->label, $expected['label']); $this->assertIdentical($config_test->style, $expected['style']); - $this->assertIdentical($config_test->langcode, LANGUAGE_NOT_SPECIFIED); + $this->assertIdentical($config_test->langcode, $default_langcode); // Verify methods on the newly created entity. $this->assertIdentical($config_test->isNew(), TRUE); diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php index 9278269d10db035064942ce922961add6c363999..03fda2a77c70f693173364c067ca4c5f7fa4391a 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php @@ -110,7 +110,7 @@ function testNew() { 'label' => 'New', 'style' => '', 'status' => '1', - 'langcode' => 'und', + 'langcode' => language_default()->langcode, 'protected_property' => '', ); $staging->write($dynamic_name, $original_dynamic_data); diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigImportUITest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigImportUITest.php index 3788d67c92b31fc3121e7b0cf65ef225cab41254..cf87bb396559cbdb523e31fec12bf4a85658873a 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigImportUITest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigImportUITest.php @@ -61,7 +61,7 @@ function testImport() { 'label' => 'New', 'style' => '', 'status' => '1', - 'langcode' => 'und', + 'langcode' => language_default()->langcode, 'protected_property' => '', ); $staging->write($dynamic_name, $original_dynamic_data); diff --git a/core/modules/contact/config/contact.category.feedback.yml b/core/modules/contact/config/contact.category.feedback.yml index 8aff8c61c25fb35d3a592056131d5737c7e46b0b..aae9098cb2b4826f05f2bff0beb66f2c460f620a 100644 --- a/core/modules/contact/config/contact.category.feedback.yml +++ b/core/modules/contact/config/contact.category.feedback.yml @@ -3,3 +3,4 @@ label: 'Website feedback' recipients: [] reply: '' weight: '0' +langcode: en diff --git a/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php b/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php index bdc98efe9b4c7b76d45a741bf191e6f3fd52b01c..1ea830b49a4e2ab67cd88840573e198dd9d8166f 100644 --- a/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php +++ b/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php @@ -82,6 +82,11 @@ function testSiteWideContact() { $this->addCategory($id = drupal_strtolower($this->randomName(16)), $label = $this->randomName(16), implode(',', array($recipients[0])), '', TRUE); $this->assertRaw(t('Category %label has been added.', array('%label' => $label))); + // Check that the category was created in site default language. + $langcode = config('contact.category.' . $id)->get('langcode'); + $default_langcode = language_default()->langcode; + $this->assertEqual($langcode, $default_langcode); + // Make sure the newly created category is included in the list of categories. $this->assertNoUniqueText($label, 'New category included in categories list.'); diff --git a/core/modules/filter/filter.admin.inc b/core/modules/filter/filter.admin.inc index e78ce67dacc03a9caf6201810330f1581a9a2abe..aa3018cf175cf317b871e0b5dcaf3637102ff59b 100644 --- a/core/modules/filter/filter.admin.inc +++ b/core/modules/filter/filter.admin.inc @@ -169,6 +169,11 @@ function filter_admin_format_form($form, &$form_state, $format) { '#disabled' => !empty($format->format), '#weight' => -20, ); + // @todo Remove once moved to FilterFormatFormController. + $form['langcode'] = array( + '#type' => 'value', + '#value' => !$format->isNew() ? $format->langcode : language_default()->langcode, + ); // Add user role access selection. $form['roles'] = array( diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterCrudTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterCrudTest.php index 21dcbf091ec4dd2b50292561dd41f88f89ec1308..7ba7b7da5c569649bf88256d27fa49f4333094d3 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterCrudTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterCrudTest.php @@ -84,6 +84,7 @@ function testTextFormatCrud() { */ function verifyTextFormat($format) { $t_args = array('%format' => $format->name); + $default_langcode = language_default()->langcode; // Verify filter_format_load(). $filter_format = filter_format_load($format->format); @@ -91,6 +92,8 @@ function verifyTextFormat($format) { $this->assertEqual($filter_format->name, $format->name, format_string('filter_format_load: Proper title for text format %format.', $t_args)); $this->assertEqual($filter_format->cache, $format->cache, format_string('filter_format_load: Proper cache indicator for text format %format.', $t_args)); $this->assertEqual($filter_format->weight, $format->weight, format_string('filter_format_load: Proper weight for text format %format.', $t_args)); + // Check that the filter was created in site default language. + $this->assertEqual($format->langcode, $default_langcode, format_string('filter_format_load: Proper language code for text format %format.', $t_args)); // Verify the 'cache' text format property according to enabled filters. $filter_info = filter_get_filters(); diff --git a/core/modules/user/config/user.role.anonymous.yml b/core/modules/user/config/user.role.anonymous.yml index 11defb06f09318cb56c9099bd3eeb022d5367abf..1947f35310c379be5049ec8211d1db851ddd644e 100644 --- a/core/modules/user/config/user.role.anonymous.yml +++ b/core/modules/user/config/user.role.anonymous.yml @@ -1,3 +1,4 @@ id: anonymous label: Anonymous user weight: 0 +langcode: en diff --git a/core/modules/user/config/user.role.authenticated.yml b/core/modules/user/config/user.role.authenticated.yml index dc4b65d6311d2b30dabb179d132612636fa7b4df..16df96d3c981c70dac4506b0b44b1fb829e977ec 100644 --- a/core/modules/user/config/user.role.authenticated.yml +++ b/core/modules/user/config/user.role.authenticated.yml @@ -1,3 +1,4 @@ id: authenticated label: Authenticated user weight: 1 +langcode: en diff --git a/core/modules/user/lib/Drupal/user/Tests/UserRoleAdminTest.php b/core/modules/user/lib/Drupal/user/Tests/UserRoleAdminTest.php index d322a640743177e4d04d0f41fce01b2fe7d6ec1b..0025873d169bfd376127c2795e0abe4576e16a5e 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserRoleAdminTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserRoleAdminTest.php @@ -32,6 +32,7 @@ function setUp() { */ function testRoleAdministration() { $this->drupalLogin($this->admin_user); + $default_langcode = language_default()->langcode; // Test adding a role. (In doing so, we use a role name that happens to // correspond to an integer, to test that the role administration pages @@ -43,6 +44,9 @@ function testRoleAdministration() { $role = entity_load('user_role', $role_name); $this->assertTrue(is_object($role), 'The role was successfully retrieved from the database.'); + // Check that the role was created in site default language. + $this->assertEqual($role->langcode, $default_langcode); + // Try adding a duplicate role. $this->drupalPost(NULL, $edit, t('Add role')); $this->assertRaw(t('The machine-readable name is already in use. It must be unique.'), 'Duplicate role warning displayed.'); diff --git a/core/modules/user/user.admin.inc b/core/modules/user/user.admin.inc index c3931d8490d449a38951730241283155090502e0..882cef2dd1bfe3c9748e274e79674201e2652dd0 100644 --- a/core/modules/user/user.admin.inc +++ b/core/modules/user/user.admin.inc @@ -1004,6 +1004,11 @@ function user_admin_role($form, $form_state, $role) { 'source' => array('role', 'label'), ), ); + // @todo Remove once moved to RoleFormController. + $form['role']['langcode'] = array( + '#type' => 'value', + '#value' => !$role->isNew() ? $role->langcode : language_default()->langcode, + ); $form['role']['weight'] = array( '#type' => 'value', '#value' => $role->weight,