Issue #3164520 by james.williams, Matroskeen, huzooka, raman.b, quietone, mikelutz: FieldableEntity::getFieldValues() does not guarantee that the returned field values are sorted by their delta
parent
62430b71d7
commit
1c17abd79c
|
@ -59,7 +59,7 @@ abstract class FieldableEntity extends DrupalSqlBase {
|
|||
* (optional) The field language.
|
||||
*
|
||||
* @return array
|
||||
* The raw field values, keyed by delta.
|
||||
* The raw field values, keyed and sorted by delta.
|
||||
*/
|
||||
protected function getFieldValues($entity_type, $field, $entity_id, $revision_id = NULL, $language = NULL) {
|
||||
$table = (isset($revision_id) ? 'field_revision_' : 'field_data_') . $field;
|
||||
|
@ -67,7 +67,8 @@ abstract class FieldableEntity extends DrupalSqlBase {
|
|||
->fields('t')
|
||||
->condition('entity_type', $entity_type)
|
||||
->condition('entity_id', $entity_id)
|
||||
->condition('deleted', 0);
|
||||
->condition('deleted', 0)
|
||||
->orderBy('delta');
|
||||
if (isset($revision_id)) {
|
||||
$query->condition('revision_id', $revision_id);
|
||||
}
|
||||
|
|
|
@ -266,7 +266,7 @@ class Node extends DrupalSqlBase {
|
|||
* The node.
|
||||
*
|
||||
* @return array
|
||||
* The field values, keyed by delta.
|
||||
* The field values, keyed and sorted by delta.
|
||||
*/
|
||||
protected function getFieldData(array $field, Row $node) {
|
||||
$field_table = 'content_' . $field['field_name'];
|
||||
|
@ -310,6 +310,7 @@ class Node extends DrupalSqlBase {
|
|||
->isNotNull($field['field_name'] . '_' . $columns[0])
|
||||
->condition('nid', $node->getSourceProperty('nid'))
|
||||
->condition('vid', $node->getSourceProperty('vid'))
|
||||
->orderBy('delta')
|
||||
->execute()
|
||||
->fetchAllAssoc('delta');
|
||||
}
|
||||
|
|
|
@ -80,6 +80,13 @@ class MigrateNodeCompleteTest extends MigrateNodeTestBase {
|
|||
foreach ($this->expectedNodeFieldRevisionTable() as $key => $revision) {
|
||||
$this->assertRevision($revision, $data[$key]);
|
||||
}
|
||||
|
||||
// Test the order in multi-value fields.
|
||||
$revision = $this->nodeStorage->loadRevision(21);
|
||||
$this->assertSame([
|
||||
['target_id' => '15'],
|
||||
['target_id' => '16'],
|
||||
], $revision->get('field_company')->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -136,6 +136,16 @@ class MigrateNodeCompleteTest extends MigrateDrupal7TestBase {
|
|||
$this->assertSame('Bob', $revision->field_user_reference[0]->entity->getAccountName());
|
||||
}
|
||||
|
||||
// Test the order in multi-value fields.
|
||||
$revision = $this->nodeStorage->loadRevision(1);
|
||||
$this->assertSame([
|
||||
['value' => 'default@example.com'],
|
||||
['value' => 'another@example.com'],
|
||||
], $revision->get('field_email')->getValue());
|
||||
$this->assertSame([
|
||||
['target_id' => '17'],
|
||||
['target_id' => '15'],
|
||||
], $revision->get('field_term_entityreference')->getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue