diff -u b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteTagsWidget.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteTagsWidget.php --- b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteTagsWidget.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteTagsWidget.php @@ -64,6 +64,7 @@ elseif ($auto_create && (count($this->instance['settings']['handler_settings']['target_bundles']) == 1 || count($bundles) == 1)) { // Auto-create item. see entity_reference_field_presave(). $value[] = array( + 'target_id' => 0, 'entity' => $this->createNewEntity($input, $element['#autocreate_uid']), ); } diff -u b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidget.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidget.php --- b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidget.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidget.php @@ -76,6 +76,7 @@ if (!$value && $auto_create && (count($this->instance['settings']['handler_settings']['target_bundles']) == 1)) { // Auto-create item. see entity_reference_field_presave(). $value = array( + 'target_id' => 0, 'entity' => $this->createNewEntity($element['#value'], $element['#autocreate_uid']), // Keep the weight property. '_weight' => $element['#weight'], only in patch2: unchanged: --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceEntityFormatter.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceEntityFormatter.php @@ -95,7 +95,7 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) { throw new RecursiveRenderingException(format_string('Recursive rendering detected when rendering entity @entity_type(@entity_id). Aborting rendering.', array('@entity_type' => $entity_type, '@entity_id' => $item['target_id']))); } - if (!empty($item['entity'])) { + if (!empty($item['target_id'])) { $entity = clone $item['entity']; unset($entity->content); $elements[$delta] = entity_view($entity, $view_mode, $langcode); @@ -107,7 +107,7 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) { } else { // This is an "auto_create" item. - $elements[$delta] = array('#markup' => $item['label']); + $elements[$delta] = array('#markup' => $entity->label()); } $depth = 0; } only in patch2: unchanged: --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceFormatterBase.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceFormatterBase.php @@ -64,7 +64,7 @@ public function prepareView(array $entities, $langcode, array &$items) { foreach ($items[$id] as $delta => $item) { // If we have a revision ID, the key uses it as well. $identifier = !empty($item['revision_id']) ? $item['target_id'] . ':' . $item['revision_id'] : $item['target_id']; - if ($item['target_id'] != 'auto_create') { + if ($item['target_id'] !== 0) { if (!isset($target_entities[$identifier])) { // The entity no longer exists, so remove the key. $rekey = TRUE; @@ -80,11 +80,7 @@ public function prepareView(array $entities, $langcode, array &$items) { } } else { - // This is an "auto_create" item, so allow access to it, as the entity - // doesn't exists yet, and we are probably in a preview. - $items[$id][$delta]['entity'] = FALSE; - // Add the label as a special key, as we cannot use entity_label(). - $items[$id][$delta]['label'] = $item['label']; + // This is an "auto_create" item, just leave the entity in place. } // Mark item as accessible. only in patch2: unchanged: --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceIdFormatter.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceIdFormatter.php @@ -34,7 +34,7 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) { $elements = array(); foreach ($items as $delta => $item) { - if (!empty($item['entity'])) { + if (!empty($item['entity']) && !empty($item['target_id'])) { $elements[$delta] = array('#markup' => check_plain($item['target_id'])); } } only in patch2: unchanged: --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceLabelFormatter.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/formatter/EntityReferenceLabelFormatter.php @@ -78,10 +78,6 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) { $elements[$delta] = array('#markup' => check_plain($label)); } } - else { - // This is an "auto_create" item. - $elements[$delta] = array('#markup' => $item['label']); - } } return $elements;