diff --git a/core/modules/field/lib/Drupal/field/FieldInfo.php b/core/modules/field/lib/Drupal/field/FieldInfo.php index e458c0f..cbd06b0 100644 --- a/core/modules/field/lib/Drupal/field/FieldInfo.php +++ b/core/modules/field/lib/Drupal/field/FieldInfo.php @@ -14,6 +14,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\field\FieldInterface; use Drupal\field\FieldInstanceInterface; +use Drupal\Core\Language\Language; /** * Provides field and instance definitions for the current runtime environment. @@ -529,8 +530,12 @@ public function getBundleExtraFields($entity_type, $bundle) { return $this->bundleExtraFields[$entity_type][$bundle]; } - // Read from the persistent cache. - if ($cached = $this->cacheBackend->get("field_info:bundle_extra:$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 = language(LANGUAGE_TYPE_INTERFACE)->langcode; + $langcode = \Drupal::languageManager()->getLanguage(Language::TYPE_INTERFACE)->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]; } @@ -545,7 +550,7 @@ public function getBundleExtraFields($entity_type, $bundle) { // Store in the 'static' and persistent caches. $this->bundleExtraFields[$entity_type][$bundle] = $info; - $this->cacheBackend->set("field_info:bundle_extra:$entity_type:$bundle", $info, CacheBackendInterface::CACHE_PERMANENT, array('field_info' => TRUE)); + $this->cacheBackend->set("field_info:bundle_extra:$langcode:$entity_type:$bundle", $info, CacheBackendInterface::CACHE_PERMANENT, array('field_info' => TRUE)); 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 267c361..44f4c3f 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldInfoTest.php @@ -7,6 +7,8 @@ namespace Drupal\field\Tests; +use Drupal\Core\Language\Language; + class FieldInfoTest extends FieldUnitTestBase { public static function getInfo() { @@ -378,4 +380,34 @@ protected function getExpectedFieldTypeDefinition() { } + + /* 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); + $locale_storage = $this->container->get('locale.storage'); + // 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( + 'lid' => $en_string->lid, + 'language' => 'xx', + 'translation' => $this->randomString(), + ))->save(); + // Check that translated strings are available in pages. + $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'); + } + + } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php index a8e6508..9bacaad 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php @@ -15,6 +15,7 @@ * Tests the functionality of the 'Manage fields' screen. */ class ManageFieldsTest extends FieldUiTestBase { + public static function getInfo() { return array( 'name' => 'Manage fields',