diff --git a/core/config/schema/core.entity.schema.yml b/core/config/schema/core.entity.schema.yml
index f6442f7..9c972c9 100644
--- a/core/config/schema/core.entity.schema.yml
+++ b/core/config/schema/core.entity.schema.yml
@@ -295,3 +295,29 @@ field.formatter.settings.entity_reference_label:
       type: boolean
       label: 'Link label to the referenced entity'
 
+field.storage_settings.dynamic_entity_reference:
+  type: mapping
+  label: 'Dynamic entity reference settings'
+  mapping:
+    target_type:
+      type: string
+      label: 'Type of item to reference'
+    exclude_entity_types:
+      type: boolean
+      label: 'Exclude the selected items'
+    entity_type_ids:
+      type: sequence
+      label: 'Entity Type IDs'
+      sequence:
+        - type: string
+          label: 'Entity Type ID'
+field.value.dynamic_entity_reference:
+  type: mapping
+  label: 'Default value'
+  mapping:
+    target_id:
+      type: string
+      label: 'Entity ID'
+    target_type:
+      type: string
+      label: 'Type of item to reference'
diff --git a/core/lib/Drupal/Core/Field/DataDynamicReferenceDefinition.php b/core/lib/Drupal/Core/Field/DataDynamicReferenceDefinition.php
new file mode 100644
index 0000000..f0a95be
--- /dev/null
+++ b/core/lib/Drupal/Core/Field/DataDynamicReferenceDefinition.php
@@ -0,0 +1,37 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Field\DataDynamicReferenceDefinition.
+ */
+
+namespace Drupal\Core\Field;
+
+use Drupal\Core\TypedData\DataReferenceDefinition;
+
+/**
+ * A typed data definition class for defining dynamic references.
+ */
+class DataDynamicReferenceDefinition extends DataReferenceDefinition {
+
+  /**
+   * @var \Drupal\Core\TypedData\DataDefinitionInterface
+   */
+  protected $targetDefinition;
+
+  /**
+   * Creates a new data reference definition.
+   *
+   * @param string $target_data_type
+   *   The data type of the referenced data.
+   *
+   * @return $this
+   */
+  public static function create($target_data_type) {
+    $definition['type'] = 'dynamic_' . $target_data_type . '_reference';
+    /* @var $definition \Drupal\Core\TypedData\DataReferenceDefinition; */
+    $definition = new static($definition);
+    return $definition->setTargetDefinition(\Drupal::typedDataManager()->createDataDefinition($target_data_type));
+  }
+
+}
diff --git a/core/lib/Drupal/Core/Field/DynamicEntityReferenceFieldItemList.php b/core/lib/Drupal/Core/Field/DynamicEntityReferenceFieldItemList.php
new file mode 100644
index 0000000..3635267
--- /dev/null
+++ b/core/lib/Drupal/Core/Field/DynamicEntityReferenceFieldItemList.php
@@ -0,0 +1,132 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Field\DynamicEntityReferenceFieldItemList.
+ */
+
+namespace Drupal\Core\Field;
+
+use Drupal\Core\Entity\FieldableEntityInterface;
+use Drupal\Core\Form\FormStateInterface;
+
+/**
+ * Defines a item list class for dynamic entity reference fields.
+ */
+class DynamicEntityReferenceFieldItemList extends EntityReferenceFieldItemList {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function referencedEntities() {
+    if (empty($this->list)) {
+      return array();
+    }
+
+    // Collect the IDs of existing entities to load, and directly grab the
+    // "autocreate" entities that are already populated in $item->entity.
+    $target_entities = $ids = array();
+    foreach ($this->list as $delta => $item) {
+      if ($item->hasNewEntity()) {
+        $target_entities[$delta] = $item->entity;
+      }
+      elseif ($item->target_id !== NULL) {
+        $ids[$item->target_type][$delta] = $item->target_id;
+      }
+    }
+
+    // Load and add the existing entities.
+    if ($ids) {
+      foreach ($ids as $target_type => $entity_type_ids) {
+        $entities = \Drupal::entityManager()
+          ->getStorage($target_type)
+          ->loadMultiple($entity_type_ids);
+        foreach ($ids as $delta => $target_id) {
+          if (isset($entities[$target_id])) {
+            $target_entities[$delta] = $entities[$target_id];
+          }
+        }
+      }
+      // Ensure the returned array is ordered by deltas.
+      ksort($target_entities);
+    }
+
+    return $target_entities;
+  }
+
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function processDefaultValue($default_value, FieldableEntityInterface $entity, FieldDefinitionInterface $definition) {
+    // We want to bypass the EntityReferenceItem::processDefaultValue()
+    $default_value = FieldItemList::processDefaultValue($default_value, $entity, $definition);
+
+    if ($default_value) {
+      // Convert UUIDs to numeric IDs.
+      $all_uuids = array();
+      foreach ($default_value as $delta => $properties) {
+        if (isset($properties['target_uuid'])) {
+          $target_type = $properties['target_type'];
+          $all_uuids[$target_type][$delta] = $properties['target_uuid'];
+        }
+      }
+      $entity_uuids = array();
+      foreach ($all_uuids as $target_type => $uuids) {
+        if ($uuids) {
+          $entity_ids = \Drupal::entityQuery($target_type)
+            ->condition('uuid', $uuids, 'IN')
+            ->execute();
+          $entities = \Drupal::entityManager()
+            ->getStorage($target_type)
+            ->loadMultiple($entity_ids);
+          $entity_uuids[$target_type] = array();
+          foreach ($entities as $id => $entity) {
+            $entity_uuids[$target_type][$entity->uuid()] = $id;
+          }
+          foreach ($uuids as $delta => $uuid) {
+            if (isset($entity_uuids[$uuid])) {
+              $default_value[$delta]['target_id'] = $entity_uuids[$target_type][$uuid];
+              $default_value[$delta]['target_type'] = $target_type;
+              unset($default_value[$delta]['target_uuid']);
+            }
+            else {
+              unset($default_value[$delta]);
+            }
+          }
+        }
+      }
+
+      // Ensure we return consecutive deltas, in case we removed unknown UUIDs.
+      $default_value = array_values($default_value);
+    }
+    return $default_value;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function defaultValuesFormSubmit(array $element, array &$form, FormStateInterface $form_state) {
+    // We want to bypass the EntityReferenceItem::defaultValuesFormSubmit()
+    $default_value = FieldItemList::defaultValuesFormSubmit($element, $form, $form_state);
+
+    // Convert numeric IDs to UUIDs to ensure config deployability.
+    $all_ids = array();
+    foreach ($default_value as $delta => $properties) {
+      $all_ids[$properties['target_type']][] = $properties['target_id'];
+    }
+    $entities = array();
+    foreach ($all_ids as $target_type => $ids) {
+      $entities[$target_type] = \Drupal::entityManager()
+        ->getStorage($target_type)
+        ->loadMultiple($ids);
+    }
+
+    foreach ($default_value as $delta => $properties) {
+      unset($default_value[$delta]['target_id']);
+      $default_value[$delta]['target_uuid'] = $entities[$properties['target_type']][$properties['target_id']]->uuid();
+    }
+    return $default_value;
+  }
+
+}
diff --git a/core/lib/Drupal/Core/Field/Plugin/DataType/DynamicEntityReference.php b/core/lib/Drupal/Core/Field/Plugin/DataType/DynamicEntityReference.php
new file mode 100644
index 0000000..d1dd091
--- /dev/null
+++ b/core/lib/Drupal/Core/Field/Plugin/DataType/DynamicEntityReference.php
@@ -0,0 +1,75 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Field\Plugin\DataType\DynamicEntityReference.
+ */
+
+namespace Drupal\Core\Field\Plugin\DataType;
+
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Entity\Plugin\DataType\EntityReference;
+
+/**
+ * Defines a 'dynamic_entity_reference' data type.
+ *
+ * This serves as 'dynamic_entity' property of entity reference field items and
+ * gets its value set from the parent.
+ *
+ * @code
+ * $definition = \Drupal\Core\Entity\EntityDefinition::create($entity_type)
+ *   ->addConstraint('Bundle', $bundle);
+ * \Drupal\Core\TypedData\DataReferenceDefinition::create('dynamic_entity')
+ *   ->setTargetDefinition($definition);
+ * @endcode
+ *
+ * @DataType(
+ *   id = "dynamic_entity_reference",
+ *   label = @Translation("Dynamic entity reference"),
+ *   definition_class = "\Drupal\Core\Field\DataDynamicReferenceDefinition"
+ * )
+ */
+class DynamicEntityReference extends EntityReference {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getTarget() {
+    if (!isset($this->target) && isset($this->id)) {
+      // If we have a valid reference, return the entity object which is typed
+      // data itself.
+      $target_type = $this->parent->getValue()['target_type'];
+      $entity = entity_load($target_type, $this->id);
+      $this->target = isset($entity) ? $entity->getTypedData() : NULL;
+    }
+    return $this->target;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setValue($value, $notify = TRUE) {
+    unset($this->target);
+    unset($this->id);
+
+    // Both the entity ID and the entity object may be passed as value. The
+    // reference may also be unset by passing NULL as value.
+    if (!isset($value)) {
+      $this->target = NULL;
+    }
+    elseif ($value instanceof EntityInterface) {
+      $this->target = $value->getTypedData();
+    }
+    elseif (!is_scalar($value) || $this->getTargetDefinition()->getEntityTypeId() === NULL) {
+      throw new \InvalidArgumentException('Value is not a valid entity.');
+    }
+    else {
+      $this->id = $value;
+    }
+    // Notify the parent of any changes.
+    if ($notify && isset($this->parent)) {
+      $this->parent->onChange($this->name);
+    }
+  }
+
+}
diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DynamicEntityReferenceItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DynamicEntityReferenceItem.php
new file mode 100644
index 0000000..6cb4f3a
--- /dev/null
+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/DynamicEntityReferenceItem.php
@@ -0,0 +1,231 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\Core\Field\Plugin\Field\FieldType\DynamicEntityReferenceItem.
+ */
+
+namespace Drupal\Core\Field\Plugin\Field\FieldType;
+
+use Drupal\Core\Config\Entity\ConfigEntityType;
+use Drupal\Core\Entity\EntityTypeInterface;
+use Drupal\Core\Field\FieldDefinitionInterface;
+use Drupal\Core\Field\FieldItemBase;
+use Drupal\Core\Field\FieldStorageDefinitionInterface;
+use Drupal\Core\TypedData\DataDefinition;
+use Drupal\Core\Field\DataDynamicReferenceDefinition;
+
+/**
+ * Defines the 'dynamic_entity_reference' entity field type.
+ *
+ * Supported settings (below the definition's 'settings' key) are:
+ * - exclude_entity_types: Allow user to include or exclude entity_types.
+ * - entity_type_ids: The entity type ids that can or cannot be referenced.
+ *
+ * @FieldType(
+ *   id = "dynamic_entity_reference",
+ *   label = @Translation("Dynamic entity reference"),
+ *   description = @Translation("An entity field containing a dynamic entity reference."),
+ *   no_ui = TRUE,
+ *   list_class = "\Drupal\Core\Field\EntityReferenceFieldItemList",
+ *   constraints = {"ValidReference" = {}}
+ * )
+ */
+class DynamicEntityReferenceItem extends EntityReferenceItem {
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function defaultStorageSettings() {
+    return array(
+      'exclude_entity_types' => TRUE,
+      'entity_type_ids' => array(),
+    );
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
+    $properties['target_id'] = DataDefinition::create('string')
+      ->setLabel(t('Entity ID'));
+    $properties['target_type'] = DataDefinition::create('string')
+      ->setLabel(t('Target Entity Type'));
+    $properties['entity'] = DataDynamicReferenceDefinition::create('entity')
+      ->setLabel(t('Entity'))
+      ->setDescription(t('The referenced entity'))
+      // The entity object is computed out of the entity ID.
+      ->setComputed(TRUE)
+      ->setReadOnly(FALSE);
+
+    return $properties;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function mainPropertyName() {
+    return 'target_id';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function schema(FieldStorageDefinitionInterface $field_definition) {
+    $columns = array(
+      'target_id' => array(
+        'description' => 'The ID of the target entity.',
+        'type' => 'varchar',
+        'length' => '255',
+      ),
+      'target_type' => array(
+        'description' => 'The Entity Type ID of the target entity.',
+        'type' => 'varchar',
+        'length' => EntityTypeInterface::BUNDLE_MAX_LENGTH,
+      ),
+    );
+
+    $schema = array(
+      'columns' => $columns,
+      'indexes' => array(
+        'target_id' => array('target_id'),
+      ),
+    );
+
+    return $schema;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function onChange($property_name, $notify = TRUE) {
+    if ($property_name == 'target_type') {
+      $this->get('entity')->getDataDefinition()->getTargetDefinition()->setEntityTypeId($this->get('target_type')->getValue());
+    }
+    // Make sure that the target type and the target property stay in sync.
+    elseif ($property_name == 'entity') {
+      $this->writePropertyValue('target_type', $this->get('entity')->getValue()->getEntityTypeId());
+    }
+    parent::onChange($property_name, $notify);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function setValue($values, $notify = TRUE) {
+    if (empty($values['target_type']) && !empty($values['target_id'])) {
+      throw new \InvalidArgumentException('No entity type was provided, value is not a valid entity.');
+    }
+    if (isset($values) && !is_array($values)) {
+      // If either a scalar or an object was passed as the value for the item,
+      // assign it to the 'entity' property since that works for both cases.
+      $this->set('entity', $values, $notify);
+    }
+    else {
+      // We have to bypass the EntityReferenceItem::setValue() here because we
+      // also want to invoke onChange for target_type.
+      FieldItemBase::setValue($values, FALSE);
+      // Support setting the field item with only one property, but make sure
+      // values stay in sync if only property is passed.
+      if (isset($values['target_id']) && !isset($values['entity'])) {
+        $this->onChange('target_type', FALSE);
+        $this->onChange('target_id', FALSE);
+      }
+      elseif (!isset($values['target_id']) && isset($values['entity'])) {
+        $this->onChange('entity', FALSE);
+      }
+      elseif (isset($values['target_id']) && isset($values['entity'])) {
+        // If both properties are passed, verify the passed values match. The
+        // only exception we allow is when we have a new entity: in this case
+        // its actual id and target_id will be different, due to the new entity
+        // marker.
+        if (($this->get('entity')->getTargetIdentifier() != $values['target_id']
+            || $this->get('entity')->getTargetDefinition()->getEntityTypeId() != $values['target_type'])) {
+          throw new \InvalidArgumentException('The target id, target type and entity passed to the dynamic entity reference item do not match.');
+        }
+      }
+      // Notify the parent if necessary.
+      if ($notify && $this->parent) {
+        $this->parent->onChange($this->getName());
+      }
+    }
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getValue($include_computed = FALSE) {
+    $values = parent::getValue($include_computed);
+    if (!empty($values['target_type'])) {
+      $this->properties['entity']->getDataDefinition()->getTargetDefinition()->setEntityTypeId($values['target_type']);
+    }
+    return $this->values;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function preSave() {
+    if ($this->hasNewEntity()) {
+      $this->entity->save();
+      $this->target_id = $this->entity->id();
+      $this->target_type = $this->entity->getEntityTypeId();
+    }
+    // Handle the case where an unsaved entity was directly set using the public
+    // 'entity' property and then saved before this entity. In this case
+    // ::hasNewEntity() will return FALSE but $this->target_id will still be
+    // empty.
+    if ((empty($this->target_id) || empty($this->target_type)) && $this->entity) {
+      $this->target_id = $this->entity->id();
+      $this->target_type = $this->entity->getEntityTypeId();
+    }
+  }
+
+  /**
+   * Helper function to get all the entity type ids that can be referenced.
+   *
+   * @param array $settings
+   *   The settings of the field storage.
+   *
+   * @return string[]
+   *   All the entity type ids that can be referenced.
+   */
+  public static function getAllEntityTypeIds($settings) {
+    $labels = \Drupal::entityManager()->getEntityTypeLabels(TRUE);
+    $options = $labels['Content'];
+
+    if ($settings['exclude_entity_types']) {
+      $entity_type_ids = array_diff_key($options, $settings['entity_type_ids'] ?: array());
+    }
+    else {
+      $entity_type_ids = array_intersect_key($options, $settings['entity_type_ids'] ?: array());
+    }
+    return $entity_type_ids;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function calculateDependencies(FieldDefinitionInterface $field_definition) {
+    $dependencies = [];
+
+    if (is_array($field_definition->default_value) && count($field_definition->default_value)) {
+      $target_entity_types = static::getAllEntityTypeIds($field_definition->getFieldStorageDefinition()->getSettings());
+      foreach ($target_entity_types as $target_entity_type) {
+        $key = $target_entity_type instanceof ConfigEntityType ? 'config' : 'content';
+        foreach ($field_definition->default_value as $default_value) {
+          if (is_array($default_value) && isset($default_value['target_uuid'])) {
+            $entity = \Drupal::entityManager()->loadEntityByUuid($target_entity_type->id(), $default_value['target_uuid']);
+            // If the entity does not exist do not create the dependency.
+            // @see \Drupal\Core\Field\EntityReferenceFieldItemList::processDefaultValue()
+            if ($entity) {
+              $dependencies[$key][] = $entity->getConfigDependencyName();
+            }
+          }
+        }
+      }
+    }
+    return $dependencies;
+  }
+
+}
diff --git a/core/modules/entity_reference/config/schema/entity_reference.schema.yml b/core/modules/entity_reference/config/schema/entity_reference.schema.yml
index 1ee04d1..8706515 100644
--- a/core/modules/entity_reference/config/schema/entity_reference.schema.yml
+++ b/core/modules/entity_reference/config/schema/entity_reference.schema.yml
@@ -70,3 +70,20 @@ field.widget.settings.entity_reference_autocomplete:
     placeholder:
       type: label
       label: 'Placeholder'
+
+field.widget.settings.dynamic_entity_reference_default:
+  type: mapping
+  label: 'Dynamic entity reference autocomplete display format settings'
+  mapping:
+    match_operator:
+      type: string
+      label: 'Autocomplete matching'
+    size:
+      type: integer
+      label: 'Size of textfield'
+    autocomplete_type:
+      type: string
+      label: 'Autocomplete type'
+    placeholder:
+      type: label
+      label: 'Placeholder'
diff --git a/core/modules/entity_reference/entity_reference.libraries.yml b/core/modules/entity_reference/entity_reference.libraries.yml
new file mode 100644
index 0000000..78ebbc8
--- /dev/null
+++ b/core/modules/entity_reference/entity_reference.libraries.yml
@@ -0,0 +1,8 @@
+drupal.dynamic_entity_reference_widget:
+  version: VERSION
+  js:
+    js/dynamic-entity-reference-widget.js: {}
+  dependencies:
+    - core/jquery
+    - core/drupal
+    - core/drupal.form
diff --git a/core/modules/entity_reference/entity_reference.routing.yml b/core/modules/entity_reference/entity_reference.routing.yml
index b2f73ff..6a6c3a9 100644
--- a/core/modules/entity_reference/entity_reference.routing.yml
+++ b/core/modules/entity_reference/entity_reference.routing.yml
@@ -5,3 +5,11 @@ entity_reference.autocomplete:
     entity_id: 'NULL'
   requirements:
     _access: 'TRUE'
+
+entity_reference.dynamic_entity_reference_autocomplete:
+  path: '/entity_reference/dynamic-autocomplete/{field_name}/{entity_type}/{bundle_name}/{target_type}/{entity_id}'
+  defaults:
+    _controller: '\Drupal\dynamic_entity_reference\DynamicEntityReferenceController::handleAutocomplete'
+    entity_id: 'NULL'
+  requirements:
+    _access: 'TRUE'
diff --git a/core/modules/entity_reference/js/dynamic-entity-reference-widget.js b/core/modules/entity_reference/js/dynamic-entity-reference-widget.js
new file mode 100644
index 0000000..b3e246b
--- /dev/null
+++ b/core/modules/entity_reference/js/dynamic-entity-reference-widget.js
@@ -0,0 +1,53 @@
+/**
+ * @file
+ * Attaches entity-type selection behaviors to the widget form.
+ */
+
+(function ($) {
+
+  "use strict";
+
+  Drupal.behaviors.dynamicEntityReferenceWidget = {
+    attach: function (context) {
+      var $context = $(context);
+      var $selects = $context.find('select.dynamic-entity-reference-entity-type').once('dynamic-entity-reference');
+      if ($selects.length) {
+        $selects.change(function() {
+          var $select = $(this);
+          var $autocomplete = $select.parents('.container-inline').find('.form-autocomplete');
+          var basePath;
+          var entityId = $autocomplete.data('entity-id');
+          if (!(basePath = $autocomplete.data('base-autocomplete-path'))) {
+            // This is the first time this has run, copy the default value.
+            var autocompletePath = $autocomplete.attr('data-autocomplete-path');
+            entityId = autocompletePath.substring(autocompletePath.lastIndexOf('/') + 1, autocompletePath.length);
+            if ($.isNumeric(entityId)) {
+              // By default, the base path contains the default suffix, so cut
+              // that off.
+              basePath = autocompletePath.substring(0, autocompletePath.lastIndexOf('/'));
+              basePath = basePath.substring(0, basePath.lastIndexOf('/') + 1);
+
+            }
+            else {
+              entityId = null;
+              // By default, the base path contains the default suffix, so cut
+              // that off.
+              basePath = autocompletePath.substring(0, autocompletePath.lastIndexOf('/') + 1);
+            }
+            // Store for subsequent calls.
+            $autocomplete.data('base-autocomplete-path', basePath);
+            $autocomplete.data('entity-id', entityId);
+          }
+          if (entityId) {
+            $autocomplete.attr('data-autocomplete-path', basePath + $select.val() + '/' + entityId);
+          }
+          else {
+            $autocomplete.attr('data-autocomplete-path', basePath + $select.val());
+          }
+        });
+        $selects.change();
+      }
+    }
+  };
+
+})(jQuery);
diff --git a/core/modules/entity_reference/src/Plugin/Field/FieldWidget/DynamicEntityReferenceWidget.php b/core/modules/entity_reference/src/Plugin/Field/FieldWidget/DynamicEntityReferenceWidget.php
new file mode 100644
index 0000000..554b563
--- /dev/null
+++ b/core/modules/entity_reference/src/Plugin/Field/FieldWidget/DynamicEntityReferenceWidget.php
@@ -0,0 +1,208 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\entity_reference\Plugin\Field\FieldWidget\DynamicEntityReferenceWidget.
+ */
+
+namespace Drupal\entity_reference\Plugin\Field\FieldWidget;
+
+use Drupal\Core\Field\FieldItemListInterface;
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\Core\Field\Plugin\Field\FieldType\DynamicEntityReferenceItem;
+use Drupal\user\EntityOwnerInterface;
+
+/**
+ * Plugin implementation of the 'dynamic_entity_reference autocomplete' widget.
+ *
+ * @FieldWidget(
+ *   id = "dynamic_entity_reference_default",
+ *   label = @Translation("Autocomplete"),
+ *   description = @Translation("An autocomplete text field."),
+ *   field_types = {
+ *     "dynamic_entity_reference"
+ *   }
+ * )
+ */
+class DynamicEntityReferenceWidget extends AutocompleteWidget {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
+    $entity = $items->getEntity();
+    $target = $items->get($delta)->entity;
+
+    $available = DynamicEntityReferenceItem::getAllEntityTypeIds($this->getFieldSettings());
+    $cardinality = $items->getFieldDefinition()->getFieldStorageDefinition()->getCardinality();
+
+    // Prepare the autocomplete route parameters.
+    $autocomplete_route_parameters = array(
+      'field_name' => $this->fieldDefinition->getName(),
+      'entity_type' => $entity->getEntityTypeId(),
+      'bundle_name' => $entity->bundle(),
+      'target_type' => $items->get($delta)->target_type ?: key($available),
+    );
+
+    if ($entity_id = $entity->id()) {
+      $autocomplete_route_parameters['entity_id'] = $entity_id;
+    }
+
+    $element += array(
+      '#type' => 'textfield',
+      '#maxlength' => 1024,
+      '#default_value' => $target ? $target->label() . ' (' . $target->id() . ')' : '',
+      '#autocomplete_route_name' => 'entity_reference.dynamic_entity_reference_autocomplete',
+      '#autocomplete_route_parameters' => $autocomplete_route_parameters,
+      '#size' => $this->getSetting('size'),
+      '#placeholder' => $this->getSetting('placeholder'),
+      '#element_validate' => array(array($this, 'elementValidate')),
+      '#autocreate_uid' => ($entity instanceof EntityOwnerInterface) ? $entity->getOwnerId() : \Drupal::currentUser()->id(),
+      '#field_name' => $items->getName(),
+    );
+
+    $element['#title'] = $this->t('Label');
+
+    $entity_type = array(
+      '#type' => 'select',
+      '#options' => $available,
+      '#title' => $this->t('Entity type'),
+      '#default_value' => $items->get($delta)->target_type,
+      '#weight' => -50,
+      '#attributes' => array(
+        'class' => array('dynamic-entity-reference-entity-type'),
+      ),
+    );
+
+    $form_element = array(
+      '#type' => 'container',
+      '#attributes' => array(
+        'class' => array('container-inline'),
+      ),
+      'target_type' => $entity_type,
+      'target_id' => $element,
+      '#attached' => array(
+        'library' => array(
+          'entity_reference/drupal.dynamic_entity_reference_widget',
+        ),
+      ),
+    );
+    // Render field as details.
+    if ($cardinality == 1) {
+      $form_element['#type'] = 'details';
+      $form_element['#title'] = $items->getFieldDefinition()->getLabel();
+      $form_element['#open'] = TRUE;
+    }
+    return $form_element;
+  }
+
+  /**
+   * Checks whether a content entity is referenced.
+   *
+   * @param string $target_type
+   *   The value target entity type.
+   *
+   * @return bool
+   *   TRUE if a content entity is referenced.
+   */
+  protected function isContentReferenced($target_type = NULL) {
+    $target_type_info = \Drupal::entityManager()->getDefinition($target_type);
+    return $target_type_info->isSubclassOf('\Drupal\Core\Entity\ContentEntityInterface');
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function elementValidate($element, FormStateInterface $form_state, $form) {
+    // If a value was entered into the autocomplete.
+    $value = NULL;
+    if (!empty($element['#value'])) {
+      // If this is the default value of the field.
+      if ($form_state->hasValue('default_value_input')) {
+        $values = $form_state->getValue(array(
+          'default_value_input',
+          $element['#field_name'],
+          $element['#delta'],
+        ));
+      }
+      else {
+        $values = $form_state->getValue(array(
+          $element['#field_name'],
+          $element['#delta'],
+        ));
+      }
+      // Take "label (entity id)', match the id from parenthesis.
+      if ($this->isContentReferenced($values['target_type']) && preg_match("/.+\((\d+)\)/", $element['#value'], $matches)) {
+        $value = $matches[1];
+      }
+      elseif (preg_match("/.+\(([\w.]+)\)/", $element['#value'], $matches)) {
+        $value = $matches[1];
+      }
+      $auto_create = $this->getHandlerSetting('auto_create', $values['target_type']);
+      // Try to get a match from the input string when the user didn't use the
+      // autocomplete but filled in a value manually.
+      if ($value === NULL) {
+        // To use entity_reference selection_handler for this target_type we
+        // have to change these settings to entity_reference field settings.
+        // @todo Remove these once https://www.drupal.org/node/1959806
+        //   and https://www.drupal.org/node/2107243 are fixed.
+        $this->fakeFieldSettings($values['target_type']);
+        /** @var \Drupal\entity_reference\Plugin\Type\Selection\SelectionInterface $handler */
+        $handler = \Drupal::service('plugin.manager.entity_reference.selection')->getSelectionHandler($this->fieldDefinition);
+        $value = $handler->validateAutocompleteInput($element['#value'], $element, $form_state, $form, !$auto_create);
+      }
+      // Auto-create item. See
+      // \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem::presave().
+      if (!$value && $auto_create && (count($this->getHandlerSetting('target_bundles', $values['target_type'])) == 1)) {
+        $value = array(
+          'target_id' => NULL,
+          'entity' => $this->createNewEntity($element['#value'], $element['#autocreate_uid']),
+          // Keep the weight property.
+          '_weight' => $element['#weight'],
+        );
+        // Change the element['#parents'], so in form_set_value() we populate
+        // the correct key.
+        array_pop($element['#parents']);
+      }
+
+    }
+    $form_state->setValueForElement($element, $value);
+  }
+
+  /**
+   * Sets the fake field settings values.
+   *
+   * These settings are required by
+   * \Drupal\entity_reference\Plugin\Type\SelectionPluginManager to select the
+   * proper selection plugin and these settings are also used by
+   * \Drupal\entity_reference\Plugin\entity_reference\selection\SelectionBase
+   * @todo Remove these once https://www.drupal.org/node/1959806
+   *   and https://www.drupal.org/node/2107243 are fixed.
+   *
+   * @param string $entity_type_id
+   *   The id of the entity type.
+   */
+  protected function fakeFieldSettings($entity_type_id) {
+    $settings = $this->getFieldSettings();
+    $this->fieldDefinition->settings['target_type'] = $entity_type_id;
+    $this->fieldDefinition->settings['handler'] = $settings[$entity_type_id]['handler'];
+    $this->fieldDefinition->settings['handler_settings'] = $settings[$entity_type_id]['handler_settings'];
+  }
+
+  /**
+   * Returns the value of a setting for the entity reference selection handler.
+   *
+   * @param string $setting_name
+   *   The setting name.
+   * @param string $entity_type_id
+   *   The id of the entity type.
+   *
+   * @return mixed
+   *   The setting value.
+   */
+  protected function getHandlerSetting($setting_name, $entity_type_id) {
+    $settings = $this->getFieldSettings();
+    return isset($settings[$entity_type_id]['handler_settings'][$setting_name]) ? $settings[$entity_type_id]['handler_settings'][$setting_name] : NULL;
+  }
+
+}
diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceIntegrationTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceIntegrationTest.php
index 6c5f8fc..4ce057d 100644
--- a/core/modules/entity_reference/src/Tests/EntityReferenceIntegrationTest.php
+++ b/core/modules/entity_reference/src/Tests/EntityReferenceIntegrationTest.php
@@ -42,11 +42,18 @@ class EntityReferenceIntegrationTest extends WebTestBase {
   protected $fieldName;
 
   /**
+   * The logged in user.
+   *
+   * @var \Drupal\user\UserInterface
+   */
+  protected $webUser;
+
+  /**
    * Modules to install.
    *
    * @var array
    */
-  public static $modules = array('config_test', 'entity_test', 'entity_reference', 'field_ui');
+  public static $modules = array('config_test', 'entity_test', 'entity_reference', 'field_ui', 'entity_reference_test');
 
   /**
    * {@inheritdoc}
@@ -55,8 +62,8 @@ protected function setUp() {
     parent::setUp();
 
     // Create a test user.
-    $web_user = $this->drupalCreateUser(array('administer entity_test content', 'administer entity_test fields'));
-    $this->drupalLogin($web_user);
+    $this->webUser = $this->drupalCreateUser(array('administer entity_test content', 'administer entity_test fields'));
+    $this->drupalLogin($this->webUser);
   }
 
   /**
@@ -78,13 +85,18 @@ public function testSupportedEntityTypesAndWidgets() {
         $this->fieldName . '[0][target_id]' => $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')',
         // Test an input of the entity label without a ' (entity_id)' suffix.
         $this->fieldName . '[1][target_id]' => $referenced_entities[1]->label(),
+        'dynamic_references[0][target_type]' => 'user',
+        'dynamic_references[0][target_id]' => $this->webUser->label() . ' (' . $this->webUser->id() . ')',
       );
       $this->drupalPostForm($this->entityType . '/add', $edit, t('Save'));
-      $this->assertFieldValues($entity_name, $referenced_entities);
+      $entity = $this->assertFieldValues($entity_name, $referenced_entities);
+      $this->assertEqual($entity->dynamic_references->target_id, $this->webUser->id());
+      $this->assertEqual($entity->dynamic_references->entity->id(), $this->webUser->id());
+      $this->assertEqual($entity->dynamic_references->entity->label(), $this->webUser->label());
+      $this->assertEqual($entity->dynamic_references->target_type, 'user');
 
       // Try to post the form again with no modification and check if the field
       // values remain the same.
-      $entity = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name)));
       $this->drupalGet($this->entityType . '/manage/' . $entity->id());
       $this->assertFieldByName($this->fieldName . '[0][target_id]', $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')');
       $this->assertFieldByName($this->fieldName . '[1][target_id]', $referenced_entities[1]->label() . ' (' . $referenced_entities[1]->id() . ')');
@@ -170,6 +182,9 @@ public function testSupportedEntityTypesAndWidgets() {
    *   The name of the test entity.
    * @param \Drupal\Core\Entity\EntityInterface[] $referenced_entities
    *   An array of referenced entities.
+   *
+   * @return \Drupal\Core\Entity\EntityInterface|FALSE
+   *   The entity with the given entity name if it exists, otherwise FALSE.
    */
   protected function assertFieldValues($entity_name, $referenced_entities) {
     $entity = current(entity_load_multiple_by_properties($this->entityType, array('name' => $entity_name)));
@@ -183,6 +198,7 @@ protected function assertFieldValues($entity_name, $referenced_entities) {
     $this->assertEqual($entity->{$this->fieldName}[1]->target_id, $referenced_entities[1]->id());
     $this->assertEqual($entity->{$this->fieldName}[1]->entity->id(), $referenced_entities[1]->id());
     $this->assertEqual($entity->{$this->fieldName}[1]->entity->label(), $referenced_entities[1]->label());
+    return $entity;
   }
 
   /**
diff --git a/core/modules/entity_reference/tests/modules/entity_reference_test/entity_reference_test.module b/core/modules/entity_reference/tests/modules/entity_reference_test/entity_reference_test.module
index 51b506b..73245b6 100644
--- a/core/modules/entity_reference/tests/modules/entity_reference_test/entity_reference_test.module
+++ b/core/modules/entity_reference/tests/modules/entity_reference_test/entity_reference_test.module
@@ -20,6 +20,15 @@ function entity_reference_test_entity_base_field_info(EntityTypeInterface $entit
       ->setDescription(t('The role of the associated user.'))
       ->setSetting('target_type', 'user_role')
       ->setSetting('handler', 'default');
+    $fields['dynamic_references'] = BaseFieldDefinition::create('dynamic_entity_reference')
+      ->setLabel(t('References'))
+      ->setDescription(t('Other references.'))
+      ->setSetting('handler', 'default')
+      ->setRequired(FALSE)
+      ->setDisplayOptions('form', [
+        'type' => 'dynamic_entity_reference_default',
+        'weight' => 10,
+      ]);
   }
 
   return $fields;
diff --git a/core/modules/system/src/Tests/Entity/EntityUnitTestBase.php b/core/modules/system/src/Tests/Entity/EntityUnitTestBase.php
index 73b9a89..c0d4ceb 100644
--- a/core/modules/system/src/Tests/Entity/EntityUnitTestBase.php
+++ b/core/modules/system/src/Tests/Entity/EntityUnitTestBase.php
@@ -179,7 +179,7 @@ protected function refreshServices() {
   protected function generateRandomEntityId($string = FALSE) {
     srand(time());
     do {
-      $id = $string ? $this->randomMachineName() : mt_rand(1, 0xFFFFFFFF);
+      $id = $string ? $this->randomMachineName() : mt_rand(1, 0xFFFFFF);
     }
     while (isset($this->generatedIds[$id]));
     $this->generatedIds[$id] = $id;
