diff --git a/core/modules/jsonld/lib/Drupal/jsonld/DrupalJsonldEntityWrapper.php b/core/modules/jsonld/lib/Drupal/jsonld/DrupalJsonldEntityWrapper.php index e8601d76e381d3962e25a8f9750794f51d0912a2..b65ffcfa00c2db83b3add4c3aa9a2e6f92b30d85 100644 --- a/core/modules/jsonld/lib/Drupal/jsonld/DrupalJsonldEntityWrapper.php +++ b/core/modules/jsonld/lib/Drupal/jsonld/DrupalJsonldEntityWrapper.php @@ -22,9 +22,10 @@ class DrupalJsonldEntityWrapper extends JsonldEntityWrapper { public function getProperties() { // Properties to skip. $skip = array('id'); + // Get default language. if ($this->entity->language()->langcode !== 'und') { - $defaultLangcode = $this->entity->language(); + $defaultLangcode = $this->entity->language()->langcode; } else { $language = variable_get('language_default'); @@ -34,16 +35,16 @@ public function getProperties() { // Process all the field values from the default translation. foreach ($this->entity as $name => $field) { $definition = $this->entity->getPropertyDefinition($name); - // Add non-translatable values. - if ($definition['translatable'] == FALSE) { - $properties[$name] = $field->getValue(); + // Add non-translatable values, keyed by langcode 'und'. + if (empty($definition['translatable'])) { + $properties[$name]['und'] = $field->getValue(); } - // Add values in the default language. + // Add translatable values, keyed by the default langcode. else { $properties[$name][$defaultLangcode] = $field->getValue(); } } - // Add translation values. + // Add in translated values for any properties with translations. foreach ($this->entity->getTranslationLanguages(FALSE) as $langcode => $language) { foreach ($this->entity->getTranslation($langcode) as $name => $field) { $properties[$name][$langcode] = $field->getValue(); diff --git a/core/modules/jsonld/lib/Drupal/jsonld/Tests/DrupalJsonldNormalizerTest.php b/core/modules/jsonld/lib/Drupal/jsonld/Tests/DrupalJsonldNormalizerTest.php index 8289db83eab2204cf8e11d790e09230621ababc0..101f6c2c6a3b20dc71325a99979f393e20c15559 100644 --- a/core/modules/jsonld/lib/Drupal/jsonld/Tests/DrupalJsonldNormalizerTest.php +++ b/core/modules/jsonld/lib/Drupal/jsonld/Tests/DrupalJsonldNormalizerTest.php @@ -8,6 +8,7 @@ namespace Drupal\jsonld\Tests; use Drupal\config\Tests\ConfigEntityTest; +use Drupal\Core\Language\Language; use Drupal\jsonld\DrupalJsonldNormalizer; use Drupal\jsonld\Tests\JsonldNormalizerTestBase; @@ -59,6 +60,13 @@ public function testSupportsNormalization() { * Tests the normalize function. */ public function testNormalize() { + // Add German as a language. + $language = new Language(array( + 'langcode' => 'de', + 'name' => 'Deutsch', + )); + language_save($language); + // Create a German entity. $values = array( 'langcode' => 'de', @@ -69,21 +77,23 @@ public function testNormalize() { 'format' => 'full_html', ), ); - - $langSpecificValues = array( + // Array of translated values. + $translationValues = array( 'name' => $this->randomName(), ); - $entity = entity_create('jsonld_test', $values); + $entity = entity_create('entity_test', $values); $entity->save(); // Add an English value for name property. - $entity->getTranslation('en')->set('name', array(0 => array('value' => $langSpecificValues['name']))); + $entity->getTranslation('en')->set('name', array(0 => array('value' => $translationValues['name']))); $expectedArray = array( '@id' => $this->getEntityId($entity), 'uuid' => array( - array( - 'value' => $entity->uuid(), + 'und' => array( + array( + 'value' => $entity->uuid() + ), ), ), 'user_id' => array( @@ -101,14 +111,16 @@ public function testNormalize() { ), 'en' => array( array( - 'value' => $langSpecificValues['name'], + 'value' => $translationValues['name'], ), ), ), 'field_test_text' => array( - array( - 'value' => $values['field_test_text']['value'], - 'format' => $values['field_test_text']['format'], + 'und' => array( + array( + 'value' => $values['field_test_text']['value'], + 'format' => $values['field_test_text']['format'], + ), ), ), ); diff --git a/core/modules/jsonld/lib/Drupal/jsonld/Tests/JsonldNormalizerTestBase.php b/core/modules/jsonld/lib/Drupal/jsonld/Tests/JsonldNormalizerTestBase.php index 989b3082171a8b324423a945170d67c440629f6d..229f77b11a7af94bf1b0b828fc8368a194408f14 100644 --- a/core/modules/jsonld/lib/Drupal/jsonld/Tests/JsonldNormalizerTestBase.php +++ b/core/modules/jsonld/lib/Drupal/jsonld/Tests/JsonldNormalizerTestBase.php @@ -19,7 +19,7 @@ * * @var array */ - public static $modules = array('entity_test'); + public static $modules = array('language', 'entity_test'); /** * Get the Entity ID.