diff --git a/core/modules/entity_reference/entity_reference.module b/core/modules/entity_reference/entity_reference.module
index 3c68c46..ae8c737 100644
--- a/core/modules/entity_reference/entity_reference.module
+++ b/core/modules/entity_reference/entity_reference.module
@@ -470,3 +470,71 @@ function entity_reference_create_instance($entity_type, $bundle, $field_name, $f
     field_create_instance($instance);
   }
 }
+
+/**
+ * Implements hook_entity_bundle_rename().
+ */
+function entity_reference_entity_bundle_rename($entity_type, $bundle_old, $bundle_new) {
+  // Reflect bundle name changes in the definitions of existing entity reference
+  // field instance.
+  foreach (field_read_instances() as $instance) {
+    $field = $instance->getField();
+    if ($field->type != 'entity_reference' || $field->settings['target_type'] != $entity_type) {
+      // Not an entity reference field, referencing the given entity type.
+      continue;
+    }
+    if (empty($instance['settings']['handler_settings']['target_bundles'])) {
+      // Instance is referencing all bundles.
+      continue;
+    }
+
+    $update_instance = FALSE;
+    foreach ($instance['settings']['handler_settings']['target_bundles'] as $delta => $bundle) {
+      if ($bundle == $bundle_old) {
+        $instance['settings']['handler_settings']['target_bundles'][$delta] = $bundle_new;
+        $update_instance = TRUE;
+      }
+    }
+    if ($update_instance) {
+      $instance->save();
+    }
+  }
+}
+
+/**
+ * Implements hook_entity_bundle_delete().
+ */
+function entity_reference_entity_bundle_delete($entity_type, $bundle) {
+  // Iterate over all entity reference fields referencing the given entity type
+  // and delete those which target only the bundle that was deleted.
+  foreach (field_read_instances() as $instance) {
+    $field = $instance->getField();
+    if ($field->type != 'entity_reference' || $field->settings['target_type'] != $entity_type) {
+      // Not an entity reference field, referencing the given entity type.
+      continue;
+    }
+    if (empty($instance['settings']['handler_settings']['target_bundles'])) {
+      // Instance is referencing all bundles.
+      continue;
+    }
+
+    $modified_instance = FALSE;
+    foreach ($instance['settings']['handler_settings']['target_bundles'] as $delta => $target_bundle) {
+      if ($target_bundle == $bundle) {
+        unset($instance['settings']['handler_settings']['target_bundles'][$delta]);
+        $modified_instance = TRUE;
+      }
+    }
+    if ($modified_instance) {
+      if (empty($instance['settings']['handler_settings']['target_bundles'])) {
+        $instance->delete();
+      }
+      else {
+        // Re-key the 'target_bundles' array.
+        $instance['settings']['handler_settings']['target_bundles'] = array_values($instance['settings']['handler_settings']['target_bundles']);
+        // Update the instance definition with the new target bundles.
+        $instance->save();
+      }
+    }
+  }
+}
diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldTest.php
new file mode 100644
index 0000000..7233374
--- /dev/null
+++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldTest.php
@@ -0,0 +1,161 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\entity_reference\Tests\EntityReferenceFieldTest.
+ */
+
+namespace Drupal\entity_reference\Tests;
+
+use Drupal\field\FieldValidationException;
+use Drupal\system\Tests\Entity\EntityUnitTestBase;
+
+/**
+ * Tests for the entity reference field.
+ */
+class EntityReferenceFieldTest extends EntityUnitTestBase {
+
+  /**
+   * The entity type used in this test.
+   *
+   * @var string
+   */
+  protected $entityType = 'entity_test';
+
+  /**
+   * The entity type that is being referenced.
+   *
+   * @var string
+   */
+  protected $referencedEntityType = 'entity_test_rev';
+
+  /**
+   * The bundle used in this test.
+   *
+   * @var string
+   */
+  protected $bundle = 'entity_test';
+
+  /**
+   * The name of the field used in this test.
+   *
+   * @var string
+   */
+  protected $fieldName = 'field_test';
+
+  /**
+   * A field array.
+   *
+   * @var array
+   */
+  protected $field;
+
+  /**
+   * An associative array of field instance data.
+   *
+   * @var array
+   */
+  protected $instance;
+
+  /**
+   * Modules to enable.
+   *
+   * @var array
+   */
+  public static $modules = array('entity_reference');
+
+  public static function getInfo() {
+    return array(
+      'name' => 'Entity Reference field',
+      'description' => 'Tests the entity reference field.',
+      'group' => 'Entity Reference',
+    );
+  }
+
+  public function setUp() {
+    parent::setUp();
+
+    $this->installSchema('system', 'variable');
+    $this->installSchema('entity_test', array('entity_test_rev', 'entity_test_rev_revision'));
+
+    // Setup a field and instance.
+    entity_reference_create_instance(
+      $this->entityType,
+      $this->bundle,
+      $this->fieldName,
+      'Field test',
+      $this->referencedEntityType,
+      'default',
+      array('target_bundles' => array($this->bundle))
+    );
+
+    $this->field = field_info_field($this->fieldName);
+    $this->instance = field_info_instance($this->entityType, $this->fieldName, $this->bundle);
+  }
+
+  /**
+   * Tests reference field validation.
+   */
+  function testEntityReferenceFieldValidation() {
+    $referenced_entity = entity_create($this->referencedEntityType, array('type' => $this->bundle));
+    $referenced_entity->save();
+
+    $entity = entity_create($this->entityType, array('type' => $this->bundle));
+    $entity->{$this->fieldName}->target_id = $referenced_entity->id();
+    try {
+      field_attach_validate($entity->getBCEntity());
+      $this->pass('Correct reference does not cause validation error.');
+    }
+    catch (FieldValidationException $e) {
+      $this->fail('Correct reference does not cause validation error.');
+    }
+
+    $bad_referenced_entity = entity_create($this->referencedEntityType, array('type' => drupal_strtolower($this->randomName())));
+    $bad_referenced_entity->save();
+
+    $entity = entity_create($this->entityType, array('type' => $this->bundle));
+    $entity->{$this->fieldName}->target_id = $bad_referenced_entity->id();
+    try {
+      field_attach_validate($entity->getBCEntity());
+      $this->fail('Wrong reference causes validation error.');
+    }
+    catch (FieldValidationException $e) {
+      $this->pass('Wrong reference causes validation error.');
+    }
+  }
+
+  /**
+   * Tests that bundle changes are mirrored in field definitions.
+   */
+  function testEntityReferenceFieldChangeMachineName() {
+    // Add several entries in the 'target_bundles' setting, to make sure that
+    // they all get updated.
+    $test_bundle_2 = drupal_strtolower($this->randomName());
+    entity_test_create_bundle($test_bundle_2, NULL, $this->referencedEntityType);
+    $this->instance['settings']['handler_settings']['target_bundles'] = array(
+      $test_bundle_2,
+      $test_bundle_2,
+      $this->bundle,
+    );
+    $this->instance->save();
+
+    // Change the machine name.
+    $test_bundle_2_new = drupal_strtolower($this->randomName());
+    entity_test_rename_bundle($test_bundle_2, $test_bundle_2_new, $this->referencedEntityType);
+
+    // Check that the field instance settings have changed.
+    $instance = field_info_instance($this->entityType, $this->fieldName, $this->bundle);
+    $target_bundles = $instance['settings']['handler_settings']['target_bundles'];
+    $this->assertEqual($target_bundles[0], $test_bundle_2_new, 'Index 0: Machine name was updated correctly.');
+    $this->assertEqual($target_bundles[1], $test_bundle_2_new, 'Index 1: Machine name was updated correctly.');
+    $this->assertEqual($target_bundles[2], $this->bundle, 'Index 2: Machine name was left untouched.');
+
+    entity_test_delete_bundle($test_bundle_2_new, $this->referencedEntityType);
+    // Check that the field instance settings have changed.
+    $instance = field_info_instance($this->entityType, $this->fieldName, $this->bundle);
+    $target_bundles = $instance['settings']['handler_settings']['target_bundles'];
+    $this->assertEqual($target_bundles[0], $this->bundle, 'Index 0: The bundle that was not removed is still referenced.');
+    $this->assertEqual(count($target_bundles[0]), 1, "The 'target_bundles' setting contains only one element.");
+  }
+
+}
