diff --git a/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php b/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php index fc3938a..51adf91 100644 --- a/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php +++ b/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php @@ -32,7 +32,6 @@ public function getInfo() { $info['#target_type'] = NULL; $info['#selection_handler'] = 'default'; $info['#selection_settings'] = array(); - $info['#host_entity_id'] = NULL; $info['#tags'] = FALSE; $info['#autocreate'] = NULL; // This should only be set to FALSE if proper validation by the selection @@ -141,7 +140,6 @@ public static function processEntityAutocomplete(array &$element, FormStateInter 'target_type' => $element['#target_type'], 'selection_handler' => $element['#selection_handler'], 'selection_settings_key' => $selection_settings_key, - 'host_entity_id' => $element['#host_entity_id'], ); return $element; diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EntityReferenceAutocompleteWidget.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EntityReferenceAutocompleteWidget.php index b2489cd..a7eb20f 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EntityReferenceAutocompleteWidget.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EntityReferenceAutocompleteWidget.php @@ -88,7 +88,10 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $referenced_entities = $items->referencedEntities(); // Append the match operation to the selection settings. - $selection_settings = $this->getFieldSetting('handler_settings') + ['match_operator' => $this->getSetting('match_operator')]; + $selection_settings = $this->getFieldSetting('handler_settings') + [ + 'match_operator' => $this->getSetting('match_operator'), + 'entity' => $entity, + ]; $element += array( '#type' => 'entity_autocomplete', @@ -111,11 +114,6 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen ); } - // Pass the ID of the referencing entity if it is available. - if (!$entity->isNew()) { - $element['#host_entity_id'] = $entity->id(); - } - return array('target_id' => $element); } diff --git a/core/modules/system/src/Controller/EntityAutocompleteController.php b/core/modules/system/src/Controller/EntityAutocompleteController.php index aa59b77..a9a89e6 100644 --- a/core/modules/system/src/Controller/EntityAutocompleteController.php +++ b/core/modules/system/src/Controller/EntityAutocompleteController.php @@ -78,9 +78,8 @@ public static function create(ContainerInterface $container) { * Thrown if the selection settings key is not found in the key/value store * or if it does not match the stored data. */ - public function handleAutocomplete(Request $request, $target_type, $selection_handler, $selection_settings_key, $host_entity_id = '') { + public function handleAutocomplete(Request $request, $target_type, $selection_handler, $selection_settings_key) { $matches = array(); - $host_entity = NULL; // Get the typed string from the URL, if it exists. if ($input = $request->query->get('q')) { @@ -104,14 +103,7 @@ public function handleAutocomplete(Request $request, $target_type, $selection_ha throw new AccessDeniedHttpException(); } - if ($host_entity_id) { - $host_entity = $this->entityTypeManager()->getStorage($target_type)->load($host_entity_id); - if (!$host_entity || !$host_entity->access('view')) { - throw new AccessDeniedHttpException(); - } - } - - $matches = $this->matcher->getMatches($target_type, $selection_handler, $selection_settings, $typed_string, $host_entity); + $matches = $this->matcher->getMatches($target_type, $selection_handler, $selection_settings, $typed_string, $selection_settings['entity']); } return new JsonResponse($matches);