diff --git a/core/modules/field/lib/Drupal/field/FieldInfo.php b/core/modules/field/lib/Drupal/field/FieldInfo.php index 61663e8..47fac8b 100644 --- a/core/modules/field/lib/Drupal/field/FieldInfo.php +++ b/core/modules/field/lib/Drupal/field/FieldInfo.php @@ -12,8 +12,7 @@ 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; /** * Provides field and instance definitions for the current runtime environment. @@ -529,8 +528,11 @@ 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 = \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]; } @@ -545,7 +547,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, Cache::PERMANENT, array('field_info' => TRUE)); + $this->cacheBackend->set("field_info:bundle_extra:$langcode:$entity_type:$bundle", $info, 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..6796899 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() { @@ -377,5 +379,38 @@ 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_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. + $en_string = $locale_storage->createString(array( + 'source' => 'User name and password', + 'context' => '', + ))->save(); + + // Create translation for new string and save it. + $translated_string = $this->randomString(); + $locale_storage->createTranslation(array( + 'lid' => $en_string->lid, + 'language' => 'hu', + 'translation' => $translated_string, + ))->save(); + + // 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'); + $this->assertEqual($user_fields['form']['account']['label'], $translated_string); + } } 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',