diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 785c81c..1d3817a 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -27,7 +27,7 @@ class Entity implements IteratorAggregate, EntityInterface { * * @var string */ - public $langcode = LANGUAGE_NOT_SPECIFIED; + public $langcode; /** * The entity type. @@ -68,6 +68,7 @@ class Entity implements IteratorAggregate, EntityInterface { */ public function __construct(array $values, $entity_type) { $this->entityType = $entity_type; + $this->langcode = language_default()->langcode; // Set initial values. foreach ($values as $key => $value) { $this->$key = $value; diff --git a/core/lib/Drupal/Core/Entity/EntityFormController.php b/core/lib/Drupal/Core/Entity/EntityFormController.php index 4a03975..6d2c9fb 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 1b0e2f8..58e87d7 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 d94e476..eee184a 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/contact/config/contact.category.feedback.yml b/core/modules/contact/config/contact.category.feedback.yml index 8aff8c6..aae9098 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 bdc98ef..1ea830b 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 806c1d7..246f286 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 f516b0c..884ea2f 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 11defb0..1947f35 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 dc4b65d..16df96d 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 d322a64..0025873 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 c3931d8..882cef2 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,