diff --git a/src/Drupal/Driver/Fields/Drupal8/EntityReferenceHandler.php b/src/Drupal/Driver/Fields/Drupal8/EntityReferenceHandler.php index 0552b6fe..143cdef0 100644 --- a/src/Drupal/Driver/Fields/Drupal8/EntityReferenceHandler.php +++ b/src/Drupal/Driver/Fields/Drupal8/EntityReferenceHandler.php @@ -14,7 +14,7 @@ public function expand($values) { $return = array(); $entity_type_id = $this->fieldInfo->getSetting('target_type'); $entity_definition = \Drupal::entityManager()->getDefinition($entity_type_id); - $label_key = $entity_definition->getKey('label'); + $label_key = $entity_definition->getKey('id'); // Determine target bundle restrictions. $target_bundle_key = NULL; @@ -31,7 +31,10 @@ public function expand($values) { $return[] = array_shift($entities); } else { - throw new \Exception(sprintf("No entity '%s' of type '%s' exists.", $value, $entity_type_id)); + // Do not throw an exception if the field has auto created items. + if (!$this->fieldConfig->getSetting('handler_settings')['auto_create']) { + throw new \Exception(sprintf("No entity '%s' of type '%s' exists.", $value, $entity_type_id)); + } } } return $return;