diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php index 50caf2f..d69a99a 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php @@ -77,10 +77,15 @@ public function formElement(FieldInterface $items, $delta, array $element, array // Prepare the autocomplete path. $autocomplete_path = $this->getSetting('autocomplete_path'); - $autocomplete_path .= '/' . $this->fieldDefinition->getFieldName() . '/' . $entity->entityType() . '/' . $entity->bundle(); - // Use as a placeholder in the URL when we don't have a real entity - // (most web servers collapse two consecutive slashes.) - $autocomplete_path .= '/' . ($entity->id() ?: 'NULL'); + $autocomplete_path .= '/' . $this->fieldDefinition->getFieldName() . '/' . $entity->entityType() . '/' . $entity->bundle() . '/'; + + // Use as a placeholder in the URL when we don't have an entity. + // Most web servers collapse two consecutive slashes. + $id = 'NULL'; + if ($entity && $entity_id = $entity->id()) { + $id = $entity_id; + } + $autocomplete_path .= $id; $element += array( '#type' => 'textfield',