diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
index 1895cfd..75ec244 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
@@ -576,7 +576,7 @@ protected function setDefaultLangcode() {
}
if (empty($this->defaultLangcode)) {
// Make sure we return a proper language object.
- $this->defaultLangcode = Language::LANGCODE_NOT_SPECIFIED;
+ $this->defaultLangcode = $this->languageManager()->getCurrentLanguage()->getId();
}
// 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/Entity/ContentEntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php
index da6890e..e7577be 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php
@@ -587,7 +587,7 @@ protected function invokeHook($hook, EntityInterface $entity) {
/**
* Maps from an entity object to the storage record.
*
- * @param \Drupal\Core\Entity\EntityInterface $entity
+ * @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The entity object.
* @param string $table_key
* (optional) The entity key identifying the target table. Defaults to
@@ -596,10 +596,9 @@ protected function invokeHook($hook, EntityInterface $entity) {
* @return \stdClass
* The record to store.
*/
- protected function mapToStorageRecord(EntityInterface $entity, $table_key = 'base_table') {
+ protected function mapToStorageRecord(ContentEntityInterface $entity, $table_key = 'base_table') {
$record = new \stdClass();
$values = array();
- $definitions = $entity->getFieldDefinitions();
$schema = drupal_get_schema($this->entityType->get($table_key));
$is_new = $entity->isNew();
@@ -611,7 +610,22 @@ protected function mapToStorageRecord(EntityInterface $entity, $table_key = 'bas
$multi_column_fields[$field] = TRUE;
continue;
}
- $values[$name] = isset($definitions[$name]) && isset($entity->$name->value) ? $entity->$name->value : NULL;
+ $values[$name] = NULL;
+ if ($entity->hasField($name)) {
+ $main_property = $entity->getFieldDefinition($name)->getMainPropertyName();
+ if ($main_property && isset($entity->get($name)->$main_property)) {
+ // If the field has a main property, store the value of that, this
+ // defaults to the first field item.
+ $values[$name] = $entity->get($name)->$main_property;
+ }
+ elseif (!$main_property) {
+ // If there is no main property, get all values from the first field
+ // item and assume that they will be stored serialized.
+ // @todo: Give field types more control over this behavior in
+ // https://drupal.org/node/2232427.
+ $values[$name] = $entity->get($name)->first()->getValue();
+ }
+ }
}
// Handle fields that store multiple properties and match each property name
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 e3192b2..7436d17 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' => Language::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/lib/Drupal/Core/Field/Plugin/Field/FieldType/MapItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/MapItem.php
index 4645b83..5ccc6d2 100644
--- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/MapItem.php
+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/MapItem.php
@@ -104,4 +104,19 @@ public function __set($name, $value) {
}
}
+ /**
+ * {@inheritdoc}
+ */
+ public static function mainPropertyName() {
+ // A map item has no main property.
+ return NULL;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function isEmpty() {
+ return empty($this->values);
+ }
+
}
diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeForm.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeForm.php
index c790efa..722db05 100644
--- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeForm.php
+++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockTypeForm.php
@@ -55,7 +55,7 @@ public function form(array $form, array &$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/lib/Drupal/content_translation/Tests/Views/TranslationLinkTest.php b/core/modules/content_translation/lib/Drupal/content_translation/Tests/Views/TranslationLinkTest.php
index e1b939c..3297e28 100644
--- a/core/modules/content_translation/lib/Drupal/content_translation/Tests/Views/TranslationLinkTest.php
+++ b/core/modules/content_translation/lib/Drupal/content_translation/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.
@@ -51,6 +52,11 @@ 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/lib/Drupal/field/Tests/DisplayApiTest.php b/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php
index 3a31e00..d7353e5 100644
--- a/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php
+++ b/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php
@@ -149,7 +149,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 ' . Language::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/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php
index 39f6e28..191a576 100644
--- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php
+++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php
@@ -180,7 +180,7 @@ function testEntityDisplayViewMultiple() {
function testFieldAttachCache() {
// Initialize random values and a test entity.
$entity_init = entity_create('entity_test', array('type' => $this->instance->bundle));
- $langcode = Language::LANGCODE_NOT_SPECIFIED;
+ $langcode = 'en';
$values = $this->_generateTestFieldValues($this->field->getCardinality());
// Non-cacheable entity type.
diff --git a/core/modules/file/lib/Drupal/file/Tests/SaveTest.php b/core/modules/file/lib/Drupal/file/Tests/SaveTest.php
index 50d6847..41f249e 100644
--- a/core/modules/file/lib/Drupal/file/Tests/SaveTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/SaveTest.php
@@ -46,12 +46,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, Language::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/lib/Drupal/hal/Normalizer/ContentEntityNormalizer.php b/core/modules/hal/lib/Drupal/hal/Normalizer/ContentEntityNormalizer.php
index f374fa3..e77be11 100644
--- a/core/modules/hal/lib/Drupal/hal/Normalizer/ContentEntityNormalizer.php
+++ b/core/modules/hal/lib/Drupal/hal/Normalizer/ContentEntityNormalizer.php
@@ -126,21 +126,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 = Language::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 f35da4d..e425bac 100644
--- a/core/modules/language/language.module
+++ b/core/modules/language/language.module
@@ -688,3 +688,11 @@ function language_system_regional_settings_form_submit($form, &$form_state) {
$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/lib/Drupal/language/DefaultLanguageItem.php b/core/modules/language/lib/Drupal/language/DefaultLanguageItem.php
new file mode 100644
index 0000000..0ef14e2
--- /dev/null
+++ b/core/modules/language/lib/Drupal/language/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/Drupal/language/Tests/EntityDefaultLanguageTest.php b/core/modules/language/tests/Drupal/language/Tests/EntityDefaultLanguageTest.php
new file mode 100644
index 0000000..0b2a3ca
--- /dev/null
+++ b/core/modules/language/tests/Drupal/language/Tests/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_entity = $this->container->get('entity.manager')->getStorage('language_entity')->create(array(
+ 'id' => 'es',
+ ));
+ $language_entity->save();
+
+ // Create a new content type which has Undefined language by default.
+ $this->createContentType('ctund', Language::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, Language::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 "und" language code when language is not specified.
+ $node = $this->createNode('ctund');
+ $this->assertEqual($node->langcode->value, Language::LANGCODE_NOT_SPECIFIED);
+ // 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 "und"
+ // language code when language is not specified.
+ $node = $this->createNode('ctes');
+ $this->assertEqual($node->langcode->value, Language::LANGCODE_NOT_SPECIFIED);
+ // 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->randomName(),
+ );
+ 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/lib/Drupal/migrate_drupal/Tests/d6/MigrateAggregatorFeedTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateAggregatorFeedTest.php
index 1110f72..5d0295f 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateAggregatorFeedTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateAggregatorFeedTest.php
@@ -8,7 +8,6 @@
namespace Drupal\migrate_drupal\Tests\d6;
use Drupal\aggregator\Entity\Feed;
-use Drupal\Core\Language\Language;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate_drupal\Tests\MigrateDrupalTestBase;
@@ -52,7 +51,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, Language::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/lib/Drupal/migrate_drupal/Tests/d6/MigrateAggregatorItemTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateAggregatorItemTest.php
index c5ca816..4ae3ca1 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateAggregatorItemTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateAggregatorItemTest.php
@@ -76,7 +76,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, Language::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/lib/Drupal/migrate_drupal/Tests/d6/MigrateCommentTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCommentTest.php
index 409f6d2..3d2da43 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCommentTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCommentTest.php
@@ -76,7 +76,7 @@ public function testComments() {
$this->assertEqual(0, $comment->pid->value);
$this->assertEqual(1, $comment->entity_id->value);
$this->assertEqual('node', $comment->entity_type->value);
- $this->assertEqual(Language::LANGCODE_NOT_SPECIFIED, $comment->language()->id);
+ $this->assertEqual('en', $comment->language()->id);
$comment = entity_load('comment', 2);
$this->assertEqual('The response to the second comment.', $comment->subject->value);
diff --git a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCustomBlockTest.php b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCustomBlockTest.php
index d48acaf..2aacd2f 100644
--- a/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCustomBlockTest.php
+++ b/core/modules/migrate_drupal/lib/Drupal/migrate_drupal/Tests/d6/MigrateCustomBlockTest.php
@@ -59,7 +59,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(Language::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);
@@ -67,7 +67,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(Language::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/node/lib/Drupal/node/Controller/NodeController.php b/core/modules/node/lib/Drupal/node/Controller/NodeController.php
index ccc3037..ffdb58d 100644
--- a/core/modules/node/lib/Drupal/node/Controller/NodeController.php
+++ b/core/modules/node/lib/Drupal/node/Controller/NodeController.php
@@ -64,13 +64,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/lib/Drupal/serialization/Tests/EntitySerializationTest.php b/core/modules/serialization/lib/Drupal/serialization/Tests/EntitySerializationTest.php
index 865704d..fdd85a6 100644
--- a/core/modules/serialization/lib/Drupal/serialization/Tests/EntitySerializationTest.php
+++ b/core/modules/serialization/lib/Drupal/serialization/Tests/EntitySerializationTest.php
@@ -87,7 +87,7 @@ public function testNormalize() {
array('value' => $this->entity->uuid()),
),
'langcode' => array(
- array('value' => Language::LANGCODE_NOT_SPECIFIED),
+ array('value' => 'en'),
),
'default_langcode' => array(
array('value' => NULL),
@@ -143,7 +143,7 @@ public function testSerialize() {
'id' => '' . $this->entity->id() . '',
'revision_id' => '' . $this->entity->getRevisionId() . '',
'uuid' => '' . $this->entity->uuid() . '',
- 'langcode' => '' . Language::LANGCODE_NOT_SPECIFIED . '',
+ 'langcode' => 'en',
'default_langcode' => '',
'name' => '' . $this->values['name'] . '',
'type' => 'entity_test_mulrev',
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/shortcut/src/Entity/Shortcut.php b/core/modules/shortcut/src/Entity/Shortcut.php
index 5807c66..03be8c8 100644
--- a/core/modules/shortcut/src/Entity/Shortcut.php
+++ b/core/modules/shortcut/src/Entity/Shortcut.php
@@ -100,15 +100,14 @@ public function setRouteName($route_name) {
* {@inheritdoc}
*/
public function getRouteParams() {
- $value = $this->get('route_parameters')->getValue();
- return reset($value);
+ return $this->get('route_parameters')->first()->getValue();
}
/**
* {@inheritdoc}
*/
public function setRouteParams($route_parameters) {
- $this->set('route_parameters', array('value' => $route_parameters));
+ $this->set('route_parameters', array($route_parameters));
return $this;
}
diff --git a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php
index 6607b7f..5a01786 100644
--- a/core/modules/shortcut/src/Tests/ShortcutLinksTest.php
+++ b/core/modules/shortcut/src/Tests/ShortcutLinksTest.php
@@ -2,7 +2,7 @@
/**
* @file
- * Definition of Drupal\shortcut\Tests\ShortcutLinksTest.
+ * Contains \Drupal\shortcut\Tests\ShortcutLinksTest.
*/
namespace Drupal\shortcut\Tests;
@@ -65,6 +65,18 @@ public function testShortcutLinkAdd() {
$this->assertTrue(in_array($this->container->get('path.alias_manager')->getPathByAlias($test['path']), $paths), 'Shortcut created: ' . $test['path']);
$this->assertLink($title, 0, 'Shortcut link found on the page.');
}
+ $saved_set = shortcut_set_load($set->id());
+ // Test that saving and re-loading a shortcut preserves its values.
+ $shortcuts = $saved_set->getShortcuts();
+ foreach ($shortcuts as $entity) {
+ // Test the node routes with parameters
+ if (strpos($entity->route_name->value, 'node.') === 0) {
+ $entity->save();
+ $loaded = entity_load('shortcut', $entity->id());
+ $this->assertEqual($entity->route_name->value, $loaded->route_name->value);
+ $this->assertEqual($entity->get('route_parameters')->first()->getValue(), $loaded->get('route_parameters')->first()->getValue());
+ }
+ }
}
/**
diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldDefaultValueTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldDefaultValueTest.php
index d624080..6ea6aeb 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldDefaultValueTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldDefaultValueTest.php
@@ -55,7 +55,7 @@ public function testDefaultValues() {
*/
protected function assertDefaultValues($entity_type) {
$entity = entity_create($entity_type);
- $this->assertEqual($entity->langcode->value, Language::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/lib/Drupal/system/Tests/Entity/EntityFieldTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php
index a838d2f..43e2b63 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php
@@ -102,6 +102,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)));
@@ -190,8 +192,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(Language::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(Language::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;
@@ -199,7 +201,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 = Language::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)));
@@ -329,8 +331,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(Language::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(Language::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)));
@@ -504,7 +506,7 @@ protected function assertDataStructureInterfaces($entity_type) {
// the user name and other user entity strings as well.
$target_strings = array(
$entity->uuid->value,
- Language::LANGCODE_NOT_SPECIFIED,
+ 'en',
$this->entity_name,
// Bundle name.
$entity->bundle(),
diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php
index 2086c14..9df65f1 100644
--- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php
+++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php
@@ -44,6 +44,13 @@ protected function _testEntityLanguageMethods($entity_type) {
'name' => 'test',
'user_id' => $this->container->get('current_user')->id(),
));
+ $this->assertEqual($entity->language()->id, $this->languageManager->getCurrentLanguage(Language::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' => $GLOBALS['user']->id(),
+ 'langcode' => Language::LANGCODE_NOT_SPECIFIED,
+ ));
$this->assertEqual($entity->language()->id, Language::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)));
@@ -149,7 +156,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' => Language::LANGCODE_NOT_SPECIFIED));
$entity->save();
$entity = entity_load($entity_type, $entity->id());
$default_langcode = $entity->language()->id;
@@ -234,6 +241,7 @@ protected function _testMultilingualProperties($entity_type) {
entity_create($entity_type, array(
'user_id' => $properties[$langcode]['user_id'],
'name' => 'some name',
+ 'langcode' => Language::LANGCODE_NOT_SPECIFIED,
))->save();
$entities = entity_load_multiple($entity_type);
@@ -296,7 +304,7 @@ function testEntityTranslationAPI() {
$langcode = $this->langcodes[1];
$entity = $this->entityManager
->getStorage('entity_test_mul')
- ->create(array('name' => $this->randomName()));
+ ->create(array('name' => $this->randomName(), 'langcode' => Language::LANGCODE_NOT_SPECIFIED));
$entity->save();
$hooks = $this->getHooksInfo();
diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php
index 0312a9d..0ddbce4 100644
--- a/core/modules/taxonomy/lib/Drupal/taxonomy/Controller/TaxonomyController.php
+++ b/core/modules/taxonomy/lib/Drupal/taxonomy/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/modules/text/lib/Drupal/text/Tests/TextWithSummaryItemTest.php b/core/modules/text/lib/Drupal/text/Tests/TextWithSummaryItemTest.php
index 9b93095..787ec88 100644
--- a/core/modules/text/lib/Drupal/text/Tests/TextWithSummaryItemTest.php
+++ b/core/modules/text/lib/Drupal/text/Tests/TextWithSummaryItemTest.php
@@ -128,7 +128,7 @@ function testProcessedCache() {
$entity = entity_load($entity_type, $entity->id());
$cache = \Drupal::cache('entity')->get("field:$entity_type:" . $entity->id());
$this->assertEqual($cache->data, array(
- Language::LANGCODE_NOT_SPECIFIED => array(
+ 'en' => array(
'summary_field' => array(
0 => array(
'value' => $value,
@@ -144,7 +144,7 @@ function testProcessedCache() {
// Inject fake processed values into the cache to make sure that these are
// used as-is and not re-calculated when the entity is loaded.
$data = array(
- Language::LANGCODE_NOT_SPECIFIED => array(
+ 'en' => array(
'summary_field' => array(
0 => array(
'value' => $value,
diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
index b4a019b..f909027 100644
--- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
@@ -149,6 +149,9 @@ public 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 6e60480..dce4710 100644
--- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityDatabaseStorageTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityDatabaseStorageTest.php
@@ -9,6 +9,7 @@
use Drupal\Core\Entity\ContentEntityDatabaseStorage;
use Drupal\Core\Field\FieldDefinition;
+use Drupal\Core\Language\Language;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -124,6 +125,11 @@ public function testCreate() {
->method('getFieldDefinitions')
->will($this->returnValue(array()));
+ $language = new Language(array('id' => 'en'));
+ $language_manager->expects($this->any())
+ ->method('getCurrentLanguage')
+ ->will($this->returnValue($language));
+
$container = new ContainerBuilder();
$container->set('language_manager', $language_manager);
$container->set('entity.manager', $entity_manager);
diff --git a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
index bc21d8a..9c20d1f 100644
--- a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
@@ -126,9 +126,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);