diff -u b/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 --- b/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 @@ -54,19 +54,11 @@ */ public function formElement(array $items, $delta, array $element, $langcode, array &$form, array &$form_state) { $field_definition = $this->field_definition; - $entity = isset($element['#entity']) ? $element['#entity'] : NULL; + $entity = $element['#entity']; // Prepare the autocomplete path. $autocomplete_path = $this->getSetting('autocomplete_path'); - $autocomplete_path .= '/' . $field_definition['field_name'] . '/' . $field_definition['entity_type'] . '/' . $field_definition['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; + $autocomplete_path .= '/' . $field_definition['field_name'] . '/' . $entity->entityType() . '/' . $entity->bundle() . '/' . $entity->id(); $element += array( '#type' => 'textfield', diff -u b/core/modules/field/tests/modules/field_test/field_test.module b/core/modules/field/tests/modules/field_test/field_test.module --- b/core/modules/field/tests/modules/field_test/field_test.module +++ b/core/modules/field/tests/modules/field_test/field_test.module @@ -224,15 +224,14 @@ */ function field_test_field_widget_form_alter(&$element, &$form_state, $context) { $field_name = $context['field_definition']['field_name']; - $entity_type = $context['field_definition']['entity_type']; - $bundle = $context['field_definition']['bundle']; - $instance = field_info_instance($entity_type, $field_name, $bundle); switch ($field_name) { case 'alter_test_text': + $instance = field_info_instance($element['value']['#entity_type'], $field_name, $element['value']['#bundle']); drupal_set_message('Field size: ' . $instance->getWidget()->getSetting('size')); break; case 'alter_test_options': + $instance = field_info_instance($element['value']['#entity_type'], $field_name, $element['value']['#bundle']); drupal_set_message('Widget type: ' . $instance->getWidget()->getPluginId()); break; }