diff --git a/core/modules/system/src/Tests/Entity/EntityFormCorrectUserInputMappingOnFieldDeltaElementsTest.php b/core/modules/system/src/Tests/Entity/EntityFormCorrectUserInputMappingOnFieldDeltaElementsTest.php
new file mode 100644
index 0000000..99ffc4a
--- /dev/null
+++ b/core/modules/system/src/Tests/Entity/EntityFormCorrectUserInputMappingOnFieldDeltaElementsTest.php
@@ -0,0 +1,112 @@
+<?php
+
+namespace Drupal\system\Tests\Entity;
+
+use Drupal\Core\Entity\ContentEntityInterface;
+use Drupal\Core\Entity\ContentEntityStorageInterface;
+use Drupal\Core\Field\FieldStorageDefinitionInterface;
+use Drupal\field\Entity\FieldConfig;
+use Drupal\field\Entity\FieldStorageConfig;
+use Drupal\simpletest\WebTestBase;
+
+/**
+ * Tests the correct mapping of user input on the correct field delta elements.
+ *
+ * @group Entity
+ */
+class EntityFormCorrectUserInputMappingOnFieldDeltaElementsTest extends WebTestBase {
+
+  protected $entity_type = 'entity_test';
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = array('entity_test');
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setUp() {
+    parent::setUp();
+    $web_user = $this->drupalCreateUser(['administer entity_test content']);
+    $this->drupalLogin($web_user);
+
+    // Create the complex field with two properties.
+    FieldStorageConfig::create(array(
+      'field_name' => 'field_reference',
+      'entity_type' => $this->entity_type,
+      'translatable' => FALSE,
+      'entity_types' => [],
+      'settings' => [
+        'target_type' => $this->entity_type,
+      ],
+      'type' => 'entity_reference_with_name_test',
+      'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
+    ))->save();
+
+    FieldConfig::create([
+      'label' => 'Entity reference test field',
+      'field_name' => 'field_reference',
+      'entity_type' => $this->entity_type,
+      'required' => TRUE,
+      'bundle' => $this->entity_type,
+      'settings' => [
+        'handler' => 'default',
+        'handler_settings' => [
+          'target_bundles' => [
+            $this->entity_type,
+          ],
+        ],
+      ],
+    ])->save();
+
+    entity_get_form_display($this->entity_type, $this->entity_type, 'default')
+      ->setComponent('field_reference', array('type' => 'entity_reference_with_name_test_widget'))
+      ->save();
+  }
+
+  /**
+   * Tests the correct user input mapping on complex fields.
+   */
+  public function testCorrectUserInputMappingOnComplexFields() {
+    /** @var ContentEntityStorageInterface $storage */
+    $storage = $this->container->get('entity_type.manager')->getStorage($this->entity_type);
+
+    /** @var ContentEntityInterface $entity1 */
+    $entity1 = $storage->create();
+    $entity1->save();
+    /** @var ContentEntityInterface $entity2 */
+    $entity2 = $storage->create();
+    $entity2->save();
+    /** @var ContentEntityInterface $entity3 */
+    $entity3 = $storage->create();
+    $entity3->save();
+
+    $entity1->set('field_reference', [
+      0 => ['target_id' => $entity2->id(), 'name' => $entity2->id()],
+      1 => ['target_id' => $entity3->id(), 'name' => $entity3->id()],
+    ]);
+    $entity1->save();
+
+    $this->drupalGet($this->entity_type . '/manage/' . $entity1->id() . '/edit');
+
+    // Rearrange the field items.
+    $edit = array(
+      'field_reference[0][_weight]' => 0,
+      'field_reference[1][_weight]' => -1,
+    );
+    $this->drupalPostForm(NULL, $edit, t('Add another item'));
+    $this->drupalPostForm(NULL, $edit, t('Save'));
+
+    $entity1 = $storage->load($entity1->id());
+
+    // Assert that after rearranging the field items the user input will be
+    // mapped on the correct delta field items.
+    foreach ($entity1->get('field_reference')->getValue() as $values) {
+      $this->assertEqual($values['target_id'], $values['name']);
+    }
+  }
+
+}
diff --git a/core/modules/system/tests/modules/entity_test/config/schema/entity_test.schema.yml b/core/modules/system/tests/modules/entity_test/config/schema/entity_test.schema.yml
index d34d949..311b2fd 100644
--- a/core/modules/system/tests/modules/entity_test/config/schema/entity_test.schema.yml
+++ b/core/modules/system/tests/modules/entity_test/config/schema/entity_test.schema.yml
@@ -14,6 +14,25 @@ field.storage_settings.shape:
       type: string
       label: 'Foreign key name'
 
+field.storage_settings.entity_reference_with_name_test:
+  type: mapping
+  label: 'Entity reference with name test field storage settings'
+  mapping:
+    target_type:
+      type: string
+      label: 'Type of item to reference'
+
+field.field_settings.entity_reference_with_name_test:
+  type: mapping
+  label: 'Entity reference with name field settings'
+  mapping:
+    handler:
+      type: string
+      label: 'Reference method'
+    handler_settings:
+      type: entity_reference_selection.[%parent.handler]
+      label: 'Entity reference selection plugin settings'
+
 entity_test.entity_test_bundle.*:
   type: config_entity
   label: 'Entity test bundle'
diff --git a/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/EntityReferenceWithNameTestItem.php b/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/EntityReferenceWithNameTestItem.php
new file mode 100644
index 0000000..e575517
--- /dev/null
+++ b/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/EntityReferenceWithNameTestItem.php
@@ -0,0 +1,61 @@
+<?php
+
+namespace Drupal\entity_test\Plugin\Field\FieldType;
+
+use Drupal\Core\Field\FieldStorageDefinitionInterface;
+use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem;
+use Drupal\Core\StringTranslation\TranslatableMarkup;
+use Drupal\Core\TypedData\DataDefinition;
+
+/**
+ * Defines the 'entity_reference_test' entity field type.
+ *
+ * Supported settings (below the definition's 'settings' key) are:
+ * - target_type: The entity type to reference. Required.
+ *
+ * @FieldType(
+ *   id = "entity_reference_with_name_test",
+ *   label = @Translation("Entity reference test field with name property"),
+ *   description = @Translation("An entity field containing an entity reference and a name property."),
+ *   category = @Translation("Reference"),
+ *   default_widget = "entity_reference_with_name_test_widget",
+ *   default_formatter = "entity_reference_label",
+ *   list_class = "\Drupal\Core\Field\EntityReferenceFieldItemList",
+ * )
+ */
+class EntityReferenceWithNameTestItem extends EntityReferenceItem  {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
+    $properties = parent::propertyDefinitions($field_definition);
+    $properties['name'] = DataDefinition::create('string')
+      ->setLabel(new TranslatableMarkup('Name'))
+      ->setRequired(TRUE);
+
+    return $properties;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function mainPropertyName() {
+    return NULL;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function schema(FieldStorageDefinitionInterface $field_definition) {
+    $schema = parent::schema($field_definition);
+    $schema['columns']['name'] = [
+      'type' => 'varchar',
+      'length' => 255,
+      'binary' => FALSE,
+    ];
+
+    return $schema;
+  }
+
+}
diff --git a/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldWidget/EntityReferenceWithNameTestWidget.php b/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldWidget/EntityReferenceWithNameTestWidget.php
new file mode 100644
index 0000000..82be0cf
--- /dev/null
+++ b/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldWidget/EntityReferenceWithNameTestWidget.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace Drupal\entity_test\Plugin\Field\FieldWidget;
+
+use Drupal\Core\Field\FieldItemListInterface;
+use Drupal\Core\Field\WidgetBase;
+use Drupal\Core\Form\FormStateInterface;
+
+/**
+ * Plugin implementation of the 'entity_reference_test' widget.
+ *
+ * @FieldWidget(
+ *   id = "entity_reference_with_name_test_widget",
+ *   label = @Translation("Entity reference with name attribute"),
+ *   field_types = {
+ *     "entity_reference_test"
+ *   },
+ * )
+ */
+class EntityReferenceWithNameTestWidget extends WidgetBase  {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
+    $element['name'] = [
+      '#type' => 'textfield',
+      '#default_value' => isset($items[$delta]->name) ? $items[$delta]->name : NULL,
+      '#size' => 255,
+    ];
+
+    $element['target_id'] = [
+      '#type' => 'hidden',
+      '#value' => $items[$delta]->target_id
+    ];
+
+    return $element;
+  }
+
+}
