diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
index aac1cbb..41d96f1 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
@@ -588,9 +588,16 @@ protected function setDefaultLangcode() {
if ($this->hasField('langcode') && ($item = $this->get('langcode')) && isset($item->language)) {
$this->defaultLangcode = $item->language->id;
}
+
if (empty($this->defaultLangcode)) {
- // Make sure we return a proper language object.
- $this->defaultLangcode = LanguageInterface::LANGCODE_NOT_SPECIFIED;
+ // Make sure we return a proper language object, if the entity has a
+ // langcode field, default to the current language.
+ if ($this->hasField('langcode')) {
+ $this->defaultLangcode = $this->languageManager()->getCurrentLanguage()->getId();
+ }
+ else {
+ $this->defaultLangcode = LanguageInterface::LANGCODE_NOT_SPECIFIED;
+ }
}
// This needs to be initialized manually as it is skipped when instantiating
// the language field object to avoid infinite recursion.
diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php
index 719a0d6..b2bcde1 100644
--- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php
+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php
@@ -91,8 +91,8 @@ public function setValue($values, $notify = TRUE) {
* {@inheritdoc}
*/
public function applyDefaultValue($notify = TRUE) {
- // Default to LANGCODE_NOT_SPECIFIED.
- $this->setValue(array('value' => LanguageInterface::LANGCODE_NOT_SPECIFIED), $notify);
+ // Default to the current site language.
+ $this->setValue(array('value' => \Drupal::languageManager()->getCurrentLanguage()->getId()), $notify);
return $this;
}
diff --git a/core/modules/block_content/src/BlockContentTypeForm.php b/core/modules/block_content/src/BlockContentTypeForm.php
index 0675657..74749dd 100644
--- a/core/modules/block_content/src/BlockContentTypeForm.php
+++ b/core/modules/block_content/src/BlockContentTypeForm.php
@@ -56,7 +56,7 @@ public function form(array $form, FormStateInterface $form_state) {
'#description' => t('Create a new revision by default for this block type.')
);
- if ($this->moduleHandler->moduleExists('content_translation')) {
+ if ($this->moduleHandler->moduleExists('language')) {
$form['language'] = array(
'#type' => 'details',
'#title' => t('Language settings'),
diff --git a/core/modules/content_translation/src/Tests/Views/TranslationLinkTest.php b/core/modules/content_translation/src/Tests/Views/TranslationLinkTest.php
index effdc6e..b37666e 100644
--- a/core/modules/content_translation/src/Tests/Views/TranslationLinkTest.php
+++ b/core/modules/content_translation/src/Tests/Views/TranslationLinkTest.php
@@ -10,6 +10,7 @@
use Drupal\views\Tests\ViewTestBase;
use Drupal\content_translation\Tests\ContentTranslationTestBase;
use Drupal\views\Tests\ViewTestData;
+use Drupal\Core\Language\Language;
/**
* Tests the content translation overview link field handler.
@@ -44,6 +45,11 @@ protected function setUp() {
$user->langcode = 'en';
$user->save();
+ // Assign user 2 LANGCODE_NOT_SPECIFIED code so entity can't be translated.
+ $user = user_load(2);
+ $user->langcode = Language::LANGCODE_NOT_SPECIFIED;
+ $user->save();
+
ViewTestData::createTestViews(get_class($this), array('content_translation_test_views'));
}
diff --git a/core/modules/field/src/Tests/DisplayApiTest.php b/core/modules/field/src/Tests/DisplayApiTest.php
index 08d0f93..623419b 100644
--- a/core/modules/field/src/Tests/DisplayApiTest.php
+++ b/core/modules/field/src/Tests/DisplayApiTest.php
@@ -7,8 +7,6 @@
namespace Drupal\field\Tests;
-use Drupal\Core\Language\LanguageInterface;
-
/**
* Tests the field display API.
*
@@ -141,7 +139,7 @@ function testFieldItemListView() {
$setting = $display['settings']['test_formatter_setting_multiple'];
$this->assertNoText($this->label, 'Label was not displayed.');
$this->assertText('field_test_entity_display_build_alter', 'Alter fired, display passed.');
- $this->assertText('entity language is ' . LanguageInterface::LANGCODE_NOT_SPECIFIED, 'Language is placed onto the context.');
+ $this->assertText('entity language is en', 'Language is placed onto the context.');
$array = array();
foreach ($this->values as $delta => $value) {
$array[] = $delta . ':' . $value['value'];
@@ -161,7 +159,7 @@ function testFieldItemListView() {
$setting = $display['settings']['test_formatter_setting_multiple'];
$this->assertRaw('visually-hidden', 'Label was visually hidden.');
$this->assertText('field_test_entity_display_build_alter', 'Alter fired, display passed.');
- $this->assertText('entity language is ' . LanguageInterface::LANGCODE_NOT_SPECIFIED, 'Language is placed onto the context.');
+ $this->assertText('entity language is en', 'Language is placed onto the context.');
$array = array();
foreach ($this->values as $delta => $value) {
$array[] = $delta . ':' . $value['value'];
diff --git a/core/modules/file/src/Tests/SaveTest.php b/core/modules/file/src/Tests/SaveTest.php
index a390b54..ee6c1a3 100644
--- a/core/modules/file/src/Tests/SaveTest.php
+++ b/core/modules/file/src/Tests/SaveTest.php
@@ -40,12 +40,11 @@ function testFileSave() {
$this->assertEqual($loaded_file->isPermanent(), $file->isPermanent(), 'Status was saved correctly.');
$this->assertEqual($file->getSize(), filesize($file->getFileUri()), 'File size was set correctly.', 'File');
$this->assertTrue($file->getChangedTime() > 1, 'File size was set correctly.', 'File');
- $this->assertEqual($loaded_file->langcode->value, LanguageInterface::LANGCODE_NOT_SPECIFIED, 'Langcode was defaulted correctly.');
+ $this->assertEqual($loaded_file->langcode->value, 'en', 'Langcode was defaulted correctly.');
// Resave the file, updating the existing record.
file_test_reset();
$file->status->value = 7;
- $file->langcode = 'en';
$file->save();
// Check that the correct hooks were called.
diff --git a/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php b/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php
index d433656..cec6b4a 100644
--- a/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php
+++ b/core/modules/hal/src/Normalizer/ContentEntityNormalizer.php
@@ -10,7 +10,6 @@
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
-use Drupal\Core\Language\LanguageInterface;
use Drupal\rest\LinkManager\LinkManagerInterface;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
@@ -126,21 +125,15 @@ public function denormalize($data, $class, $format = NULL, array $context = arra
// Create the entity.
$typed_data_ids = $this->getTypedDataIds($data['_links']['type']);
+ $values = array();
// Figure out the language to use.
if (isset($data['langcode'])) {
- $langcode = $data['langcode'][0]['value'];
+ $values['langcode'] = $data['langcode'][0]['value'];
// Remove the langcode so it does not get iterated over below.
unset($data['langcode']);
}
- elseif ($this->moduleHandler->moduleExists('language')) {
- $langcode = language_get_default_langcode($typed_data_ids['entity_type'], $typed_data_ids['bundle']);
- }
- else {
- $langcode = LanguageInterface::LANGCODE_NOT_SPECIFIED;
- }
$entity_type = $this->entityManager->getDefinition($typed_data_ids['entity_type']);
- $values = array('langcode' => $langcode);
if ($entity_type->hasKey('bundle')) {
$bundle_key = $entity_type->getKey('bundle');
diff --git a/core/modules/language/language.module b/core/modules/language/language.module
index e8dc588..cbec3d5 100644
--- a/core/modules/language/language.module
+++ b/core/modules/language/language.module
@@ -680,3 +680,11 @@ function language_system_regional_settings_form_submit($form, FormStateInterface
$language->default = TRUE;
language_save($language);
}
+
+/**
+ * Implements hook_field_info_alter().
+ */
+function language_field_info_alter(&$info) {
+ // Change the default behavior of language field.
+ $info['language']['class'] = '\Drupal\language\DefaultLanguageItem';
+}
diff --git a/core/modules/language/src/DefaultLanguageItem.php b/core/modules/language/src/DefaultLanguageItem.php
new file mode 100644
index 0000000..0ef14e2
--- /dev/null
+++ b/core/modules/language/src/DefaultLanguageItem.php
@@ -0,0 +1,54 @@
+getEntity()) {
+ $langcode = $this->getDefaultLangcode($entity);
+ }
+ // Always notify otherwise default langcode will not be set correctly.
+ $this->setValue(array('value' => $langcode), TRUE);
+ return $this;
+ }
+
+ /**
+ * Provides default language code of given entity.
+ *
+ * @param \Drupal\Core\Entity\EntityInterface $entity
+ * The entity whose language code to be loaded.
+ *
+ * @return string
+ * A string language code.
+ */
+ public function getDefaultLangcode(EntityInterface $entity) {
+ return language_get_default_langcode($entity->getEntityTypeId(), $entity->bundle());
+ }
+
+}
diff --git a/core/modules/language/tests/src/EntityDefaultLanguageTest.php b/core/modules/language/tests/src/EntityDefaultLanguageTest.php
new file mode 100644
index 0000000..c7ec49c
--- /dev/null
+++ b/core/modules/language/tests/src/EntityDefaultLanguageTest.php
@@ -0,0 +1,151 @@
+ 'Entity default language',
+ 'description' => 'Test that entities are created with correct language code.',
+ 'group' => 'Entity API',
+ );
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setUp() {
+ parent::setUp();
+
+ // Activate Spanish language, so there are two languages activated.
+ $language = $this->container->get('entity.manager')->getStorage('configurable_language')->create(array(
+ 'id' => 'es',
+ ));
+ $language->save();
+
+ // Create a new content type which has Undefined language by default.
+ $this->createContentType('ctund', LanguageInterface::LANGCODE_NOT_SPECIFIED);
+ // Create a new content type which has Spanish language by default.
+ $this->createContentType('ctes', 'es');
+ }
+
+ /**
+ * Tests that default language code is properly set for new nodes.
+ */
+ public function testEntityTranslationDefaultLanguageViaCode() {
+ // With language module activated, and a content type that is configured to
+ // have no language by default, a new node of this content type will have
+ // "und" language code when language is not specified.
+ $node = $this->createNode('ctund');
+ $this->assertEqual($node->langcode->value, LanguageInterface::LANGCODE_NOT_SPECIFIED);
+ // With language module activated, and a content type that is configured to
+ // have no language by default, a new node of this content type will have
+ // "es" language code when language is specified as "es".
+ $node = $this->createNode('ctund', 'es');
+ $this->assertEqual($node->langcode->value, 'es');
+
+ // With language module activated, and a content type that is configured to
+ // have language "es" by default, a new node of this content type will have
+ // "es" language code when language is not specified.
+ $node = $this->createNode('ctes');
+ $this->assertEqual($node->langcode->value, 'es');
+ // With language module activated, and a content type that is configured to
+ // have language "es" by default, a new node of this content type will have
+ // "en" language code when language "en" is specified.
+ $node = $this->createNode('ctes', 'en');
+ $this->assertEqual($node->langcode->value, 'en');
+
+ // Disable language module.
+ $this->disableModules(array('language'));
+
+ // With language module disabled, and a content type that is configured to
+ // have no language specified by default, a new node of this content type
+ // will have site's default language code when language is not specified.
+ $node = $this->createNode('ctund');
+ $this->assertEqual($node->langcode->value, 'en');
+ // With language module disabled, and a content type that is configured to
+ // have no language specified by default, a new node of this type will have
+ // "es" language code when language "es" is specified.
+ $node = $this->createNode('ctund', 'es');
+ $this->assertEqual($node->langcode->value, 'es');
+
+ // With language module disabled, and a content type that is configured to
+ // have language "es" by default, a new node of this type will have site's
+ // default language code when language is not specified.
+ $node = $this->createNode('ctes');
+ $this->assertEqual($node->langcode->value, 'en');
+ // With language module disabled, and a content type that is configured to
+ // have language "es" by default, a new node of this type will have "en"
+ // language code when language "en" is specified.
+ $node = $this->createNode('ctes', 'en');
+ $this->assertEqual($node->langcode->value, 'en');
+ }
+
+ /**
+ * Creates a new node content type.
+ *
+ * @param name
+ * The content type name.
+ * @param $langcode
+ * Default language code of the nodes of this type.
+ */
+ protected function createContentType($name, $langcode) {
+ $content_type = $this->container->get('entity.manager')->getStorage('node_type')->create(array(
+ 'name' => 'Test ' . $name,
+ 'title_label' => 'Title',
+ 'type' => $name,
+ 'create_body' => FALSE,
+ ));
+ $content_type->save();
+ language_save_default_configuration('node', $name, array(
+ 'langcode' => $langcode,
+ 'language_show' => FALSE,
+ ));
+ }
+
+ /**
+ * Creates a new node of given type and language using Entity API.
+ *
+ * @param $type
+ * The node content type.
+ * @param $langcode
+ * (optional) Language code to pass to entity create.
+ *
+ * @return \Drupal\node\NodeInterface
+ * The node created.
+ */
+ protected function createNode($type, $langcode = NULL) {
+ $values = array(
+ 'type' => $type,
+ 'title' => $this->randomString(),
+ );
+ if (!empty($langcode)) {
+ $values['langcode'] = $langcode;
+ }
+ $node = $this->container->get('entity.manager')->getStorage('node')->create($values);
+ return $node;
+ }
+
+}
diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateAggregatorFeedTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateAggregatorFeedTest.php
index 93bba9b..66bc81f 100644
--- a/core/modules/migrate_drupal/src/Tests/d6/MigrateAggregatorFeedTest.php
+++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateAggregatorFeedTest.php
@@ -8,7 +8,6 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\aggregator\Entity\Feed;
-use Drupal\Core\Language\LanguageInterface;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase;
@@ -43,7 +42,7 @@ public function testAggregatorFeedImport() {
$feed = entity_load('aggregator_feed', 5);
$this->assertNotNull($feed->uuid());
$this->assertEqual($feed->title->value, 'Know Your Meme');
- $this->assertEqual($feed->language()->id, LanguageInterface::LANGCODE_NOT_SPECIFIED);
+ $this->assertEqual($feed->language()->id, 'en');
$this->assertEqual($feed->url->value, 'http://knowyourmeme.com/newsfeed.rss');
$this->assertEqual($feed->refresh->value, 900);
$this->assertEqual($feed->checked->value, 1387659487);
diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateAggregatorItemTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateAggregatorItemTest.php
index c2df201..b2c200a 100644
--- a/core/modules/migrate_drupal/src/Tests/d6/MigrateAggregatorItemTest.php
+++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateAggregatorItemTest.php
@@ -67,7 +67,7 @@ public function testAggregatorItem() {
$this->assertEqual($item->getDescription(), "
What's new with Drupal 8?
");
$this->assertEqual($item->getLink(), 'https://groups.drupal.org/node/395218');
$this->assertEqual($item->getPostedTime(), 1389297196);
- $this->assertEqual($item->language()->id, LanguageInterface::LANGCODE_NOT_SPECIFIED);
+ $this->assertEqual($item->language()->id, 'en');
$this->assertEqual($item->getGuid(), '395218 at https://groups.drupal.org');
}
diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateBlockContentTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateBlockContentTest.php
index 519ed77..0835650 100644
--- a/core/modules/migrate_drupal/src/Tests/d6/MigrateBlockContentTest.php
+++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateBlockContentTest.php
@@ -51,7 +51,7 @@ public function testBlockMigration() {
$this->assertEqual('My block 1', $block->label());
$this->assertEqual(1, $block->getRevisionId());
$this->assertTrue(REQUEST_TIME <= $block->getChangedTime() && $block->getChangedTime() <= time());
- $this->assertEqual(LanguageInterface::LANGCODE_NOT_SPECIFIED, $block->language()->id);
+ $this->assertEqual('en', $block->language()->id);
$this->assertEqual('My first custom block body
', $block->body->value);
$this->assertEqual('full_html', $block->body->format);
@@ -59,7 +59,7 @@ public function testBlockMigration() {
$this->assertEqual('My block 2', $block->label());
$this->assertEqual(2, $block->getRevisionId());
$this->assertTrue(REQUEST_TIME <= $block->getChangedTime() && $block->getChangedTime() <= time());
- $this->assertEqual(LanguageInterface::LANGCODE_NOT_SPECIFIED, $block->language()->id);
+ $this->assertEqual('en', $block->language()->id);
$this->assertEqual('My second custom block body
', $block->body->value);
$this->assertEqual('full_html', $block->body->format);
}
diff --git a/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTest.php b/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTest.php
index b8aaa32..77980cd 100644
--- a/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTest.php
+++ b/core/modules/migrate_drupal/src/Tests/d6/MigrateCommentTest.php
@@ -81,7 +81,7 @@ public function testComments() {
$this->assertEqual(0, $comment->pid->target_id);
$this->assertEqual(1, $comment->getCommentedEntityId());
$this->assertEqual('node', $comment->getCommentedEntityTypeId());
- $this->assertEqual(LanguageInterface::LANGCODE_NOT_SPECIFIED, $comment->language()->id);
+ $this->assertEqual('en', $comment->language()->id);
$this->assertEqual('comment_no_subject', $comment->getTypeId());
$comment = entity_load('comment', 2);
diff --git a/core/modules/node/src/Controller/NodeController.php b/core/modules/node/src/Controller/NodeController.php
index e983eee..3382c0b 100644
--- a/core/modules/node/src/Controller/NodeController.php
+++ b/core/modules/node/src/Controller/NodeController.php
@@ -92,13 +92,11 @@ public function addPage() {
*/
public function add(NodeTypeInterface $node_type) {
$account = $this->currentUser();
- $langcode = $this->moduleHandler()->invoke('language', 'get_default_langcode', array('node', $node_type->type));
$node = $this->entityManager()->getStorage('node')->create(array(
'uid' => $account->id(),
'name' => $account->getUsername() ?: '',
'type' => $node_type->type,
- 'langcode' => $langcode ? $langcode : $this->languageManager()->getCurrentLanguage()->id,
));
$form = $this->entityFormBuilder()->getForm($node);
diff --git a/core/modules/serialization/src/Tests/EntitySerializationTest.php b/core/modules/serialization/src/Tests/EntitySerializationTest.php
index deb55b2..849b271 100644
--- a/core/modules/serialization/src/Tests/EntitySerializationTest.php
+++ b/core/modules/serialization/src/Tests/EntitySerializationTest.php
@@ -77,7 +77,7 @@ public function testNormalize() {
array('value' => $this->entity->uuid()),
),
'langcode' => array(
- array('value' => LanguageInterface::LANGCODE_NOT_SPECIFIED),
+ array('value' => 'en'),
),
'name' => array(
array('value' => $this->values['name']),
@@ -132,7 +132,7 @@ public function testSerialize() {
$expected = array(
'id' => '' . $this->entity->id() . '',
'uuid' => '' . $this->entity->uuid() . '',
- 'langcode' => '' . LanguageInterface::LANGCODE_NOT_SPECIFIED . '',
+ 'langcode' => 'en',
'name' => '' . $this->values['name'] . '',
'type' => 'entity_test_mulrev',
'user_id' => '' . $this->values['user_id'] . '',
diff --git a/core/modules/shortcut/src/Controller/ShortcutController.php b/core/modules/shortcut/src/Controller/ShortcutController.php
index 8f3b481..943caa0 100644
--- a/core/modules/shortcut/src/Controller/ShortcutController.php
+++ b/core/modules/shortcut/src/Controller/ShortcutController.php
@@ -9,7 +9,6 @@
use Drupal\Core\Controller\ControllerBase;
use Drupal\shortcut\ShortcutSetInterface;
-use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides route responses for taxonomy.module.
@@ -28,9 +27,6 @@ class ShortcutController extends ControllerBase {
*/
public function addForm(ShortcutSetInterface $shortcut_set) {
$shortcut = $this->entityManager()->getStorage('shortcut')->create(array('shortcut_set' => $shortcut_set->id()));
- if ($this->moduleHandler()->moduleExists('language')) {
- $shortcut->langcode = language_get_default_langcode('shortcut', $shortcut_set->id());
- }
return $this->entityFormBuilder()->getForm($shortcut, 'add');
}
diff --git a/core/modules/system/src/Tests/Entity/EntityFieldDefaultValueTest.php b/core/modules/system/src/Tests/Entity/EntityFieldDefaultValueTest.php
index 89e0752..cd7f237 100644
--- a/core/modules/system/src/Tests/Entity/EntityFieldDefaultValueTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityFieldDefaultValueTest.php
@@ -49,7 +49,7 @@ public function testDefaultValues() {
*/
protected function assertDefaultValues($entity_type) {
$entity = entity_create($entity_type);
- $this->assertEqual($entity->langcode->value, LanguageInterface::LANGCODE_NOT_SPECIFIED, String::format('%entity_type: Default language', array('%entity_type' => $entity_type)));
+ $this->assertEqual($entity->langcode->value, 'en', String::format('%entity_type: Default language', array('%entity_type' => $entity_type)));
$this->assertTrue(Uuid::isValid($entity->uuid->value), String::format('%entity_type: Default UUID', array('%entity_type' => $entity_type)));
$this->assertEqual($entity->name->getValue(), array(0 => array('value' => NULL)), 'Field has one empty value by default.');
}
diff --git a/core/modules/system/src/Tests/Entity/EntityFieldTest.php b/core/modules/system/src/Tests/Entity/EntityFieldTest.php
index 2166b4c..c69d2cf 100644
--- a/core/modules/system/src/Tests/Entity/EntityFieldTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityFieldTest.php
@@ -106,6 +106,8 @@ public function testReadWrite() {
protected function assertReadWrite($entity_type) {
$entity = $this->createTestEntity($entity_type);
+ $langcode = 'en';
+
// Access the name field.
$this->assertTrue($entity->name instanceof FieldItemListInterface, format_string('%entity_type: Field implements interface', array('%entity_type' => $entity_type)));
$this->assertTrue($entity->name[0] instanceof FieldItemInterface, format_string('%entity_type: Field item implements interface', array('%entity_type' => $entity_type)));
@@ -194,8 +196,8 @@ protected function assertReadWrite($entity_type) {
$this->assertFalse(isset($entity->name->value), format_string('%entity_type: Name is not set.', array('%entity_type' => $entity_type)));
// Access the language field.
- $this->assertEqual(LanguageInterface::LANGCODE_NOT_SPECIFIED, $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type)));
- $this->assertEqual(\Drupal::languageManager()->getLanguage(LanguageInterface::LANGCODE_NOT_SPECIFIED), $entity->langcode->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($langcode, $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual(\Drupal::languageManager()->getLanguage($langcode), $entity->langcode->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type)));
// Change the language by code.
$entity->langcode->value = \Drupal::languageManager()->getDefaultLanguage()->id;
@@ -203,7 +205,7 @@ protected function assertReadWrite($entity_type) {
$this->assertEqual(\Drupal::languageManager()->getDefaultLanguage(), $entity->langcode->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type)));
// Revert language by code then try setting it by language object.
- $entity->langcode->value = LanguageInterface::LANGCODE_NOT_SPECIFIED;
+ $entity->langcode->value = $langcode;
$entity->langcode->language = \Drupal::languageManager()->getDefaultLanguage();
$this->assertEqual(\Drupal::languageManager()->getDefaultLanguage()->id, $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual(\Drupal::languageManager()->getDefaultLanguage(), $entity->langcode->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type)));
@@ -333,8 +335,8 @@ protected function assertSave($entity_type) {
// Access the name field.
$this->assertEqual(1, $entity->id->value, format_string('%entity_type: ID value can be read.', array('%entity_type' => $entity_type)));
$this->assertTrue(is_string($entity->uuid->value), format_string('%entity_type: UUID value can be read.', array('%entity_type' => $entity_type)));
- $this->assertEqual(LanguageInterface::LANGCODE_NOT_SPECIFIED, $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type)));
- $this->assertEqual(\Drupal::languageManager()->getLanguage(LanguageInterface::LANGCODE_NOT_SPECIFIED), $entity->langcode->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual('en', $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type)));
+ $this->assertEqual(\Drupal::languageManager()->getLanguage('en'), $entity->langcode->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entity_user->id(), $entity->user_id->target_id, format_string('%entity_type: User id can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entity_user->getUsername(), $entity->user_id->entity->name->value, format_string('%entity_type: User name can be read.', array('%entity_type' => $entity_type)));
$this->assertEqual($this->entity_field_text, $entity->field_test_text->value, format_string('%entity_type: Text field can be read.', array('%entity_type' => $entity_type)));
@@ -508,7 +510,7 @@ protected function assertDataStructureInterfaces($entity_type) {
// the user name and other user entity strings as well.
$target_strings = array(
$entity->uuid->value,
- LanguageInterface::LANGCODE_NOT_SPECIFIED,
+ 'en',
$this->entity_name,
// Bundle name.
$entity->bundle(),
diff --git a/core/modules/system/src/Tests/Entity/EntityTranslationTest.php b/core/modules/system/src/Tests/Entity/EntityTranslationTest.php
index 7ee45c2..56bec61 100644
--- a/core/modules/system/src/Tests/Entity/EntityTranslationTest.php
+++ b/core/modules/system/src/Tests/Entity/EntityTranslationTest.php
@@ -38,7 +38,13 @@ protected function _testEntityLanguageMethods($entity_type) {
'name' => 'test',
'user_id' => $this->container->get('current_user')->id(),
));
- $this->assertEqual($entity->language()->id, LanguageInterface::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Entity language not specified.', array('%entity_type' => $entity_type)));
+ $this->assertEqual($entity->language()->getId(), $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->id, format_string('%entity_type: Entity created with API has default language.', array('%entity_type' => $entity_type)));
+ $entity = entity_create($entity_type, array(
+ 'name' => 'test',
+ 'user_id' => \Drupal::currentUser()->id(),
+ 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
+ ));
+ $this->assertEqual($entity->language()->getId(), LanguageInterface::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Entity language not specified.', array('%entity_type' => $entity_type)));
$this->assertFalse($entity->getTranslationLanguages(FALSE), format_string('%entity_type: No translations are available', array('%entity_type' => $entity_type)));
// Set the value in default language.
@@ -143,7 +149,7 @@ protected function _testMultilingualProperties($entity_type) {
// Create a language neutral entity and check that properties are stored
// as language neutral.
- $entity = entity_create($entity_type, array('name' => $name, 'user_id' => $uid));
+ $entity = entity_create($entity_type, array('name' => $name, 'user_id' => $uid, 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
$entity->save();
$entity = entity_load($entity_type, $entity->id());
$default_langcode = $entity->language()->id;
@@ -228,6 +234,7 @@ protected function _testMultilingualProperties($entity_type) {
entity_create($entity_type, array(
'user_id' => $properties[$langcode]['user_id'],
'name' => 'some name',
+ 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
))->save();
$entities = entity_load_multiple($entity_type);
@@ -290,7 +297,7 @@ function testEntityTranslationAPI() {
$langcode = $this->langcodes[1];
$entity = $this->entityManager
->getStorage('entity_test_mul')
- ->create(array('name' => $this->randomMachineName()));
+ ->create(array('name' => $this->randomMachineName(), 'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED));
$entity->save();
$hooks = $this->getHooksInfo();
diff --git a/core/modules/taxonomy/src/Controller/TaxonomyController.php b/core/modules/taxonomy/src/Controller/TaxonomyController.php
index 0312a9d..0ddbce4 100644
--- a/core/modules/taxonomy/src/Controller/TaxonomyController.php
+++ b/core/modules/taxonomy/src/Controller/TaxonomyController.php
@@ -11,7 +11,6 @@
use Drupal\Core\Controller\ControllerBase;
use Drupal\taxonomy\TermInterface;
use Drupal\taxonomy\VocabularyInterface;
-use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides route responses for taxonomy.module.
@@ -29,9 +28,6 @@ class TaxonomyController extends ControllerBase {
*/
public function addForm(VocabularyInterface $taxonomy_vocabulary) {
$term = $this->entityManager()->getStorage('taxonomy_term')->create(array('vid' => $taxonomy_vocabulary->id()));
- if ($this->moduleHandler()->moduleExists('language')) {
- $term->langcode = language_get_default_langcode('taxonomy_term', $taxonomy_vocabulary->id());
- }
return $this->entityFormBuilder()->getForm($term);
}
diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
index dfd6b47..5226be2 100644
--- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
@@ -138,6 +138,9 @@ protected function setUp() {
->method('getLanguage')
->with('en')
->will($this->returnValue($language));
+ $this->languageManager->expects($this->any())
+ ->method('getCurrentLanguage')
+ ->will($this->returnValue($language));
$this->fieldTypePluginManager = $this->getMockBuilder('\Drupal\Core\Field\FieldTypePluginManager')
->disableOriginalConstructor()
diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityDatabaseStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityDatabaseStorageTest.php
index 3d52694..fde0d84 100644
--- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityDatabaseStorageTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityDatabaseStorageTest.php
@@ -12,6 +12,7 @@
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition;
+use Drupal\Core\Language\Language;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -1026,6 +1027,11 @@ public function testFieldSqlSchemaForEntityWithStringIdentifier() {
public function testCreate() {
$language_manager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
+ $language = new Language(array('id' => 'en'));
+ $language_manager->expects($this->any())
+ ->method('getCurrentLanguage')
+ ->will($this->returnValue($language));
+
$this->container->set('language_manager', $language_manager);
$this->container->set('entity.manager', $this->entityManager);
$this->container->set('module_handler', $this->moduleHandler);
diff --git a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
index f3447ba..5c69511 100644
--- a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
@@ -113,9 +113,13 @@ protected function setUpKeyValueEntityStorage($uuid_key = 'uuid') {
$this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface');
$this->uuidService = $this->getMock('Drupal\Component\Uuid\UuidInterface');
$this->languageManager = $this->getMock('Drupal\Core\Language\LanguageManagerInterface');
+ $language = new Language(array('langcode' => 'en'));
$this->languageManager->expects($this->any())
->method('getDefaultLanguage')
- ->will($this->returnValue(new Language(array('langcode' => 'en'))));
+ ->will($this->returnValue($language));
+ $this->languageManager->expects($this->any())
+ ->method('getCurrentLanguage')
+ ->will($this->returnValue($language));
$this->entityStorage = new KeyValueEntityStorage($this->entityType, $this->keyValueStore, $this->uuidService, $this->languageManager);
$this->entityStorage->setModuleHandler($this->moduleHandler);