diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php index 391e3444..af3c2cb 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -523,7 +523,13 @@ protected function loadFromSharedTables(array &$values, array &$translations) { if ($data_fields) { $fields = array_merge($fields, $data_fields); $query->leftJoin($this->dataTable, 'data', "(revision.$this->idKey = data.$this->idKey)"); - $query->fields('data', $data_fields); + $column_names = []; + // Some fields can have more then once columns in the data table so we + // need column names. + foreach ($data_fields as $data_field) { + $column_names = array_merge($column_names, array_values($table_mapping->getColumnNames($data_field))); + } + $query->fields('data', $column_names); } // Get the revision IDs. diff --git a/core/modules/system/tests/modules/entity_reference_test/entity_reference_test.module b/core/modules/system/tests/modules/entity_reference_test/entity_reference_test.module index 93a9be1..54f3757 100644 --- a/core/modules/system/tests/modules/entity_reference_test/entity_reference_test.module +++ b/core/modules/system/tests/modules/entity_reference_test/entity_reference_test.module @@ -7,7 +7,6 @@ use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; -use Drupal\Core\Field\FieldStorageDefinitionInterface; /** * Implements hook_entity_base_field_info(). @@ -28,8 +27,7 @@ function entity_reference_test_entity_base_field_info(EntityTypeInterface $entit ->setDescription(t('The test reference field.')) ->setSetting('target_type', 'entity_test_mulrev') ->setSetting('handler', 'default') - ->setSetting('handler_settings', ['target_bundles' => ['entity_test_rev']]) - ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED); + ->setSetting('handler_settings', ['target_bundles' => ['entity_test_rev']]); } return $fields; diff --git a/core/modules/system/tests/modules/entity_test/entity_test.module b/core/modules/system/tests/modules/entity_test/entity_test.module index 3acb3d3..2e08068 100644 --- a/core/modules/system/tests/modules/entity_test/entity_test.module +++ b/core/modules/system/tests/modules/entity_test/entity_test.module @@ -117,8 +117,7 @@ function entity_test_entity_base_field_info(EntityTypeInterface $entity_type) { if ($entity_type->id() == 'entity_test_mulrev' && \Drupal::state()->get('entity_test.multi_column')) { $fields['description'] = BaseFieldDefinition::create('shape') ->setLabel(t('Some custom description')) - ->setTranslatable(TRUE) - ->setDefaultValueCallback('entity_test_field_default_value'); + ->setTranslatable(TRUE); } return $fields; diff --git a/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityNonRevisionableFieldTest.php b/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityNonRevisionableFieldTest.php index 36cdd46..73684e9 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityNonRevisionableFieldTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/ContentEntityNonRevisionableFieldTest.php @@ -183,44 +183,28 @@ public function testMultiColumnNonRevisionableBaseField() { // Refresh the storage. $this->mulRev = $this->entityManager->getStorage('entity_test_mulrev'); $user1 = $this->createUser(); - $langcode1 = 'en'; - $langcode2 = 'de'; // Create a test entity. $entity = EntityTestMulRev::create([ 'name' => $this->randomString(), 'user_id' => $user1->id(), - 'language' => $langcode1, + 'language' => 'en', 'non_rev_field' => 'Huron', + 'description' => [ + 'shape' => 'shape', + 'color' => 'color', + ], ]); $entity->save(); $entity = $this->mulRev->loadUnchanged($entity->id()); $expected = [ [ - 'shape' => "shape:0:description_$langcode1", - 'color' => "color:0:description_$langcode1", - ], - [ - 'shape' => "shape:1:description_$langcode1", - 'color' => "color:1:description_$langcode1", + 'shape' => 'shape', + 'color' => 'color', ], ]; $this->assertEquals('Huron', $entity->get('non_rev_field')->value, 'Huron found on entity 1'); - $this->assertEqual($entity->description->getValue(), $expected); - $this->assertEqual($entity->description->getLangcode(), $langcode1, 'Field object has the expected langcode.'); - $translation = $entity->addTranslation($langcode2); - $expected = [ - [ - 'shape' => "shape:0:description_$langcode2", - 'color' => "color:0:description_$langcode2", - ], - [ - 'shape' => "shape:1:description_$langcode2", - 'color' => "color:1:description_$langcode2", - ], - ]; - $this->assertEqual($translation->description->getValue(), $expected, 'Language-aware default values correctly populated.'); - $this->assertEqual($translation->description->getLangcode(), $langcode2, 'Field object has the expected langcode.'); + $this->assertEquals($expected, $entity->description->getValue()); } } diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityReferenceBaseFieldTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityReferenceBaseFieldTest.php deleted file mode 100644 index c16b180..0000000 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityReferenceBaseFieldTest.php +++ /dev/null @@ -1,166 +0,0 @@ -set('entity_reference_test.entity_test_rev', TRUE); - $this->installEntitySchema($this->entityType); - $this->installEntitySchema($this->referencedEntityType); - } - - /** - * Tests reference field validation. - */ - public function testEntityReferenceFieldValidation() { - // Test a valid reference. - $referenced_entity = $this->container->get('entity_type.manager') - ->getStorage($this->referencedEntityType) - ->create(array('type' => $this->bundle)); - $referenced_entity->save(); - - $entity = $this->container->get('entity_type.manager') - ->getStorage($this->entityType) - ->create(array('type' => $this->bundle)); - $entity->{$this->fieldName}->target_id = $referenced_entity->id(); - $violations = $entity->{$this->fieldName}->validate(); - $this->assertEqual($violations->count(), 0, 'Validation passes.'); - - // Test an invalid reference. - $entity->{$this->fieldName}->target_id = 9999; - $violations = $entity->{$this->fieldName}->validate(); - $this->assertEqual($violations->count(), 1, 'Validation throws a violation.'); - $this->assertEqual($violations[0]->getMessage(), t('The referenced entity (%type: %id) does not exist.', array('%type' => $this->referencedEntityType, '%id' => 9999))); - - // Test a non-referenceable bundle. - entity_test_create_bundle('non_referenceable', NULL, $this->referencedEntityType); - $referenced_entity = entity_create($this->referencedEntityType, array('type' => 'non_referenceable')); - $referenced_entity->save(); - $entity->{$this->fieldName}->target_id = $referenced_entity->id(); - $violations = $entity->{$this->fieldName}->validate(); - $this->assertEqual($violations->count(), 1, 'Validation throws a violation.'); - $this->assertEqual($violations[0]->getMessage(), t('This entity (%type: %id) cannot be referenced.', array('%type' => $this->referencedEntityType, '%id' => $referenced_entity->id()))); - } - - /** - * Tests the multiple target entities loader. - */ - public function testReferencedEntitiesMultipleLoad() { - // Create the parent entity. - $entity = $this->container->get('entity_type.manager') - ->getStorage($this->entityType) - ->create(array('type' => $this->bundle)); - - // Create three target entities and attach them to parent field. - $target_entities = array(); - $reference_field = array(); - for ($i = 0; $i < 3; $i++) { - $target_entity = $this->container->get('entity_type.manager') - ->getStorage($this->referencedEntityType) - ->create(array('type' => $this->bundle)); - $target_entity->save(); - $target_entities[] = $target_entity; - $reference_field[]['target_id'] = $target_entity->id(); - } - - // Also attach a non-existent entity and a NULL target id. - $reference_field[3]['target_id'] = 99999; - $target_entities[3] = NULL; - $reference_field[4]['target_id'] = NULL; - $target_entities[4] = NULL; - - // Attach the first created target entity as the sixth item ($delta == 5) of - // the parent entity field. We want to test the case when the same target - // entity is referenced twice (or more times) in the same entity reference - // field. - $reference_field[5] = $reference_field[0]; - $target_entities[5] = $target_entities[0]; - - // Create a new target entity that is not saved, thus testing the - // "autocreate" feature. - $target_entity_unsaved = $this->container->get('entity_type.manager') - ->getStorage($this->referencedEntityType) - ->create(array('type' => $this->bundle, 'name' => $this->randomString())); - $reference_field[6]['entity'] = $target_entity_unsaved; - $target_entities[6] = $target_entity_unsaved; - - // Set the field value. - $entity->{$this->fieldName}->setValue($reference_field); - - // Load the target entities using EntityReferenceField::referencedEntities(). - $entities = $entity->{$this->fieldName}->referencedEntities(); - - // Test returned entities: - // - Deltas must be preserved. - // - Non-existent entities must not be retrieved in target entities result. - foreach ($target_entities as $delta => $target_entity) { - if (!empty($target_entity)) { - if (!$target_entity->isNew()) { - // There must be an entity in the loaded set having the same id for - // the same delta. - $this->assertEqual($target_entity->id(), $entities[$delta]->id()); - } - else { - // For entities that were not yet saved, there must an entity in the - // loaded set having the same label for the same delta. - $this->assertEqual($target_entity->label(), $entities[$delta]->label()); - } - } - else { - // A non-existent or NULL entity target id must not return any item in - // the target entities set. - $this->assertFalse(isset($entities[$delta])); - } - } - } - -}