diff --git a/core/modules/field/lib/Drupal/field/FieldInfo.php b/core/modules/field/lib/Drupal/field/FieldInfo.php index d910d58..47fac8b 100644 --- a/core/modules/field/lib/Drupal/field/FieldInfo.php +++ b/core/modules/field/lib/Drupal/field/FieldInfo.php @@ -12,8 +12,6 @@ use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Field\FieldTypePluginManager; use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\field\FieldInterface; -use Drupal\field\FieldInstanceInterface; use Drupal\Core\Language\Language; /** @@ -533,7 +531,7 @@ public function getBundleExtraFields($entity_type, $bundle) { // Read from the persistent cache. Since hook_field_extra_fields() and // hook_field_extra_fields_alter() might contain t() calls, we cache per // language. - $langcode = \Drupal::languageManager()->getLanguage(Language::TYPE_INTERFACE)->id; + $langcode = \Drupal::languageManager()->getCurrentLanguage()->id; if ($cached = $this->cacheBackend->get("field_info:bundle_extra:$langcode:$entity_type:$bundle")) { $this->bundleExtraFields[$entity_type][$bundle] = $cached->data; return $this->bundleExtraFields[$entity_type][$bundle]; diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php index 44f4c3f..6796899 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php @@ -379,35 +379,38 @@ protected function getExpectedFieldTypeDefinition() { ); } - - - /* Tests that the extra fields can be translated. + /** + * Tests that the extra fields can be translated. */ function testFieldInfoExtraFieldsTranslation() { $this->enableModules(array('language', 'locale')); $this->installSchema('locale', array('locales_source', 'locales_target')); - $language = new Language(array('id' => 'xx')); - language_save($language); + $language_en = new Language(array('id' => 'en', 'langcode' => 'en', 'default' => TRUE)); + language_save($language_en); + $language_hu = new Language(array('id' => 'hu', 'langcode' => 'en')); + language_save($language_hu); $locale_storage = $this->container->get('locale.storage'); - // Create test source string + + // Create test source string. $en_string = $locale_storage->createString(array( 'source' => 'User name and password', 'context' => '', ))->save(); - // Create translation for new string and save it. - $translation = $locale_storage->createTranslation(array( + + // Create translation for new string and save it. + $translated_string = $this->randomString(); + $locale_storage->createTranslation(array( 'lid' => $en_string->lid, - 'language' => 'xx', - 'translation' => $this->randomString(), + 'language' => 'hu', + 'translation' => $translated_string, ))->save(); - // Check that translated strings are available in pages. + + // Check that the label is translated. + $language_hu->default = TRUE; + language_save($language_hu); $field_info = \Drupal::service('field.info'); $user_fields = $field_info->getBundleExtraFields('user', 'user'); - $label = $user_fields['form']['account']['label']; - $translation = $locale_storage->getTranslations(array('lid' => $translation->lid)); - $this->assertNotNull($translation[0]->translation, 'Translated string found.'); - $this->assertNotNull($label, 'User name and password'); + $this->assertEqual($user_fields['form']['account']['label'], $translated_string); } - }