diff --git a/core/modules/field/lib/Drupal/field/FieldInfo.php b/core/modules/field/lib/Drupal/field/FieldInfo.php index 7ff6850..479a50e 100644 --- a/core/modules/field/lib/Drupal/field/FieldInfo.php +++ b/core/modules/field/lib/Drupal/field/FieldInfo.php @@ -442,8 +442,11 @@ public function getBundleExtraFields($entity_type, $bundle) { return $this->bundleExtraFields[$entity_type][$bundle]; } - // Read from the persistent cache. - if ($cached = cache('field')->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; + if ($cached = cache('field')->get("field_info:bundle_extra:$langcode:$entity_type:$bundle")) { $this->bundleExtraFields[$entity_type][$bundle] = $cached->data; return $this->bundleExtraFields[$entity_type][$bundle]; } @@ -461,7 +464,7 @@ public function getBundleExtraFields($entity_type, $bundle) { // Store in the 'static' and persistent caches. $this->bundleExtraFields[$entity_type][$bundle] = $info; - cache('field')->set("field_info:bundle_extra:$entity_type:$bundle", $info, CacheBackendInterface::CACHE_PERMANENT, array('field_info' => TRUE)); + cache('field')->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_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php old mode 100644 new mode 100755 index cbc132f..b07847f --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php @@ -7,10 +7,19 @@ namespace Drupal\field_ui\Tests; +use Drupal\Core\Language\Language; + /** * Tests the functionality of the 'Manage fields' screen. */ class ManageFieldsTest extends FieldUiTestBase { + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('language', 'locale'); + public static function getInfo() { return array( 'name' => 'Manage fields', @@ -472,5 +481,31 @@ function testDeleteTaxonomyField() { // Check that the field was deleted too. $this->assertNull(field_info_field($this->field_name), 'Field was deleted.'); } + + /** + * Test that _field_info_collate_fields() is not localized + */ + function testFieldTranslation() { + $admin_user = $this->drupalCreateUser(array('administer user fields', 'access administration pages')); + $this->drupalLogin($admin_user); + $language = new Language(array('langcode' => 'xx')); + language_save($language); + // Create test source string + $en_string = locale_storage()->createString(array( + 'source' => 'User name and password', + 'context' => $this->randomName(10), + ))->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 translated strings are avialable in pages. + $this->drupalGet('xx/admin/config/people/accounts/fields'); + $this->assertText($translation->getString(), 'Translated string found.'); + $this->drupalGet('admin/config/people/accounts/fields'); + $this->assertText($en_string->getString(), 'English string found.'); + } }