Widgets for entity reference fields are responsible for passing along the entity the widget is rendered on (aka host entity) so entity reference selection plugins know about the entity making the request.

The options buttons (checkbox/radio) and options select pass along the entity. These widgets create selection settings via:

  1. \Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase::getOptions
  2. \Drupal\Core\TypedData\OptionsProviderInterface::getSettableOptions
  3. \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManager::getSelectionHandler

The entity autocomplete is not passing along the entity. Its selection settings are created in \Drupal\Core\Field\Plugin\Field\FieldWidget\EntityReferenceAutocompleteWidget::formElement

Steps to reproduce:

Select widget

  1. Set up an entity reference field and reference it to content.
  2. Use the select list widget for the entity reference field.
  3. Edit an entity with the entity reference field.
  4. When the form is being rendered, inspect \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::getReferenceableEntities, notice $this->configuration['entity'] contains the entity the field is rendered on.

Autocomplete widget

  1. Set up an entity reference field and reference it to content.
  2. Use the autocomplete widget for the entity reference field.
  3. Edit an entity with the entity reference field.
  4. When the form is being rendered, inspect \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::getReferenceableEntities, notice $this->configuration['entity'] does not exist.

Proposed solution

- In the EntityReferenceAutocompleteWidget FieldWidget, pass the entity to the $selection_settings.
- Add a new #autocomplete_query_parameters property on the Element EntityAutocomplete if the $selection_settings['entity'] is an instance of EntityInterface. This property can handle the entity_type_id and the entity_id of the current entity being edited. We unset then the $selection_settings['entity'] set before to not have a different $selection_settings_key for each entity
- In the FormElement Element, for element with the property #autocomplete_route_name, check if the element has also the #autocomplete_query_parameters property, and if so pass theses parameters as query parameters to the Url built.
- In the EntityAutocompleteController of the system module, we can check now for query parameter 'entity_type_id' and 'entity_id' present in the URL and so load the entity and re-pass it to the $selection_settings
- And now we have the current entity in any EntityReferenceSelection plugin with an autocomplete widget

CommentFileSizeAuthor
#96 2826826-autocomplete_host_entity-96.patch14.48 KBvasike
#86 2826826-86.patch10.32 KBsmustgrave
#77 2826826-77.patch8.31 KBshubham chandra
#76 2826826-76.patch10.73 KBzarpele
#70 interdiff_69-70.txt1.48 KBranjith_kumar_k_u
#70 2826826-70.patch10.34 KBranjith_kumar_k_u
#69 core-autocomplete-context-2826826-69.patch10.29 KBrwohleb
#68 core-autocomplete-context-2826826-68.patch10.34 KBrwohleb
#62 interdiff_60-62.txt1.68 KBraman.b
#62 2826826-62.patch10.43 KBraman.b
#60 interdiff_58-60.txt8.31 KBraman.b
#60 2826826-60.patch10.66 KBraman.b
#58 interdiff_56-58.txt899 bytesraman.b
#58 2826826-58.patch11.27 KBraman.b
#56 2826826-autocomplete_host_entity-56.patch11.27 KBmrinalini9
#53 2826826-autocomplete_host_entity-53.patch11.04 KBgpap
#47 2826826-autocomplete_host_entity-47.patch11.16 KBjohnnydarkko
#45 2826826-autocomplete_host_entity-45.patch11.11 KBmpolishchuck
#43 2826826-43.patch10.92 KBgpap
#42 2826826-42.patch11.29 KBjibran
#42 interdiff-b0d512.txt769 bytesjibran
#40 2826826-40.patch11.34 KBjibran
#32 2826826-autocomplete_host_entity-32--in-query.patch10.93 KBmpolishchuck
#26 interdiff-2826826-20-26--in-field-route.txt8.35 KBdpi
#26 interdiff-2826826-20-26--in-route.txt6.95 KBdpi
#26 2826826-autocomplete-host-entity-26--field-route.patch13.06 KBdpi
#26 2826826-autocomplete-host-entity-26--in-route.patch12.46 KBdpi
#20 2826826-autocomplete-host-entity-20.patch11.33 KBdpi
#20 interdiff-2826826-18-20.txt1.17 KBdpi
#18 2826826-autocomplete-host-entity-18.patch11.29 KBdpi
#18 interdiff-2826826-14-18.txt1.94 KBdpi
#14 interdiff-2826826-9-14.txt3.06 KBdpi
#14 2826826-autocomplete-host-entity-14.patch10.41 KBdpi
#9 2826826-autocomplete-host-entity-tests-only.patch6.09 KBdpi
#9 2826826-autocomplete-host-entity.patch7.06 KBdpi

Issue fork drupal-2826826

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

RoySegall created an issue. See original summary.

amitaibu’s picture

Issue summary: View changes
amitaibu’s picture

Issue summary: View changes

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dpi’s picture

dpi’s picture

Title: Entity reference selection handler does not aware of current entity when using autocomplete widget » Entity autocomplete widget does not pass along entity to AJAX request
Version: 8.4.x-dev » 8.5.x-dev
Assigned: Unassigned » dpi
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new7.06 KB
new6.09 KB

I don't think we should be attempting to solve this bug in a feature request. This issue concerns the autocomplete widget, whereas the #2280479: Add setting to EntityReferenceSelection plugins to prevent references to referencing entity should concern selection plugins only, and is therefore widget agnostic.

The existing patch (currently at comment #2280479-41: Add setting to EntityReferenceSelection plugins to prevent references to referencing entity) is solving the problem incorrectly, by adding an extra part to the `system.entity_autocomplete` route. The entity can be unpacked out of selection settings, so adding a host ID to the entity selection route is unnecessary.

Attached patch is new work, not a derivative of #2280479: Add setting to EntityReferenceSelection plugins to prevent references to referencing entity.

jibran’s picture

+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EntityReferenceAutocompleteWidget.php
@@ -88,7 +88,10 @@ class EntityReferenceAutocompleteWidget extends WidgetBase {
+      'entity' => $entity,

So this well end up in \Drupal::keyValue('entity_autocomplete'). It will keep increasing the size of table. It will also serialize the entity as well.

jibran’s picture

+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EntityReferenceAutocompleteWidget.php
@@ -88,7 +88,10 @@ class EntityReferenceAutocompleteWidget extends WidgetBase {
+      'entity' => $entity,

We can just send the uuid.

dpi’s picture

The other side is \Drupal\system\Controller\EntityAutocompleteController::handleAutocomplete handles autocompletes whether they are for entity_autocomplete attached to entities or regular forms.

Existing code may be sending along entity objects in KV. So we'd have to use a different settings key. Also some entities don't implement UUIDs, so theres even more to handle.

Status: Needs review » Needs work

The last submitted patch, 9: 2826826-autocomplete-host-entity-tests-only.patch, failed testing. View results

dpi’s picture

Status: Needs work » Needs review
StatusFileSize
new10.41 KB
new3.06 KB

#9 contains expected fails.

Attached patch addresses feedback where entity is serialised. Entity keys are now extracted and serialised, then reversed on the autocomplete request.

dpi’s picture

Issue summary: View changes
jibran’s picture

+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EntityReferenceAutocompleteWidget.php
@@ -88,7 +88,10 @@ class EntityReferenceAutocompleteWidget extends WidgetBase {
+      'entity' => $entity,

Do we want to check for #entity->isNew() before passing?

Status: Needs review » Needs work

The last submitted patch, 14: 2826826-autocomplete-host-entity-14.patch, failed testing. View results

dpi’s picture

Status: Needs work » Needs review
StatusFileSize
new1.94 KB
new11.29 KB

@ #16

Accounted for unsaved entities.

Status: Needs review » Needs work

The last submitted patch, 18: 2826826-autocomplete-host-entity-18.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

dpi’s picture

Status: Needs work » Needs review
StatusFileSize
new1.17 KB
new11.33 KB

Fixed entity_type being set despite not having any ids.

berdir’s picture

As mentioned in IRC, the problem with adding even just the entity id/UUID to those options is that we create entity * entity reference key value entries.

The key is based on the hash, so an ID/UUID in there results in a different hash for every entity. At the very least, we would need to switch to an expirable key value store, so we can clean them up but it is still a non-trivial overhead that is being added.

jibran’s picture

The key is based on the hash, so an ID/UUID in there results in a different hash for every entity. At the very least, we would need to switch to an expirable key value store, so we can clean them up but it is still a non-trivial overhead that is being added.

+++ b/core/modules/system/system.routing.yml
@@ -501,9 +501,10 @@ system.admin_content:
-  path: '/entity_reference_autocomplete/{target_type}/{selection_handler}/{selection_settings_key}'
+  path: '/entity_reference_autocomplete/{target_type}/{selection_handler}/{selection_settings_key}/{host_entity_type_id}/{host_entity_uuid/host_entity_id}'

If that's the case then passing it in the URL seems much better than storing it.

dpi’s picture

Assigned: dpi » Unassigned

@ #22

If that's the case then passing it in the URL seems much better than storing it.

Is it going to be a problem that users can enter any origin entity_type/id? We'd have to make sure the user has the same access as it does to the entity form that embedded the entity reference field.

My vote is switching to a expirable backend per #21.

amateescu’s picture

Is it going to be a problem that users can enter any origin entity_type/id? We'd have to make sure the user has the same access as it does to the entity form that embedded the entity reference field.

Yes, we would need to validate that the entity type / entity ID combination received in the URL matches the entity type / entity ID we're currently editing. We can do that in \Drupal\Core\Entity\Element\EntityAutocomplete::processEntityAutocomplete() where we construct the route parameters for the system.entity_autocomplete route.

This approach has the advantage that it doesn't clobber the key/value (expirable) store with a lot of unneeded data, so it would be my preferred way to solve this issue.

jibran’s picture

We'd have to make sure the user has the same access as it does to the entity form that embedded the entity reference field.

That won't be a problem because \Drupal\Core\Entity\Element\EntityAutocomplete::getEntityLabels makes sure user can't see the inaccessible entity labels. I can't think of a scenario where the user can't have access to host entity because the user is creating/editing it.

In case, someone brute force last two param of '/entity_reference_autocomplete/{target_type}/{selection_handler}/{selection_settings_key}/{host_entity_type_id}/{host_entity_uuid/host_entity_id}' and directly access the URI \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection::buildEntityQuery still won't show the inaccessible entities.

Yes, I think \Drupal\Core\Entity\Element\EntityAutocomplete::processEntityAutocomplete() is the place to add the param.

Thank you @amateescu for having a look at both issues and suggesting a path forward.

Edit: Fixed the wrong paste.

dpi’s picture

As discussed with @jibran and @amateescu on Dslack:

Identifiers in route

I see that the problem of passing arbritary entity type/ID combos is still a concern for #24 / #25. I fear that selection plugins may trust the entity given to them is the real entity generating the request. Which is what putting the ID's into the key store solves.

Ive created a patch in 2826826-autocomplete-host-entity-26--in-route.patch

Field details in route

An alternative implementation, is to completely bypass key value storage, creating a new route. This would direction would apply to base/attached fields only. See 2826826-autocomplete-host-entity-26--field-route.patch

New route would be: '/entity_reference_autocomplete/{field-or-base-id}/{host-entity-id}':

  • Route is very neat. (Compared to new route in above patch)
  • Get target entity type from field settings.
  • Get host entity type via field info
  • Get live selection settings from field settings.
  • Avoids KV entirely.
  • Patch doesnt consider base fields yet.
  • Extra access control: checks if currentUser can edit the field via field access system.
  • Method is coupled to field system. Non entity reference autocompletes dont have a "host entity", and can still use existing route..

The last submitted patch, 26: 2826826-autocomplete-host-entity-26--in-route.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work

The last submitted patch, 26: 2826826-autocomplete-host-entity-26--field-route.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

dpi’s picture

Status: Needs work » Needs review

Patches are experimental only

Seeking direction before thorough code review.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Status: Needs review » Needs work

The last submitted patch, 26: 2826826-autocomplete-host-entity-26--field-route.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mpolishchuck’s picture

I think another way to implement this (passing host entity info in query parameters) deserves to exist. At least it works for me.

Note: the host entity is available on autocomplete only for editing existing entity. For new entity the entity config param of selection plugin will be still NULL.

mpolishchuck’s picture

Status: Needs work » Needs review

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

heddn’s picture

Tagging as this is blocking OG Vocab.

heddn’s picture

Status: Needs review » Needs work

from #25:

I can't think of a scenario where the user can't have access to host entity because the user is creating/editing it.

OG is a scenario I can think of. Autocomplete w/ view that filters by OG. User has access to add blog posts and page but not create/modify the group entity itself. The OG entity id is what is passed to the autocomplete for filtering all content related to the OG.

+++ b/core/modules/system/src/Controller/EntityAutocompleteController.php
@@ -106,4 +109,41 @@ class EntityAutocompleteController extends ControllerBase {
+    $host = \Drupal::entityTypeManager()
+      ->getStorage($host_entity_type)
+      ->load($entity_id);
+    if (!$host) {
+      // Triggers on field setting form.
+      return [];
+    }
+
+    if (!$host->{$field_name}->access('edit')) {

I don't think we can assume the entity will always be the host entity. Or at least for the use case I want to use w/ organic groups, it isn't. I want to pass the OG and filter a view of content by the group entity. In that case, the field would be on one entity and the entity context would just be that. Context for a contextual filter.

martijn de wit’s picture

Did add a test for php7.2.

PHP 7.2 & MySQL 5.5 Patch Failed to Apply

Don't know why its failing...

dhirendra.mishra’s picture

Assigned: Unassigned » dhirendra.mishra

will work on comment from #36

dhirendra.mishra’s picture

Assigned: dhirendra.mishra » Unassigned
jibran’s picture

Status: Needs review » Needs work

The last submitted patch, 40: 2826826-40.patch, failed testing. View results

jibran’s picture

Status: Needs work » Needs review
StatusFileSize
new769 bytes
new11.29 KB
+++ b/core/tests/Drupal/FunctionalJavascriptTests/EntityReference/EntityReferenceAutocompleteWidgetTest.php
@@ -99,4 +101,49 @@ public function testEntityReferenceAutocompleteWidget() {
+    $this->assertSession()->statusCodeEquals(200);

.

gpap’s picture

StatusFileSize
new10.92 KB

[deleted]

Status: Needs review » Needs work

The last submitted patch, 43: 2826826-43.patch, failed testing. View results

mpolishchuck’s picture

StatusFileSize
new11.11 KB

Modification of #43 (patch for 8.6.7).
Seems like new DrupalSelenium2Driver for the tests does not allow to check server response code. So I'm removing that line from the test for the moment. Anyway if something will go wrong - crawler won't find required element in DOM...

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

johnnydarkko’s picture

StatusFileSize
new11.16 KB

Reroll of #45 for 8.7.x and 8.8.x.

martijn de wit’s picture

Status: Needs work » Needs review

set issue to "needs review". So we can get a RTbtC :)

amateescu’s picture

@heddn, for the OG use case you mentioned in #36 I think you will need #1699378: Allow tokens in entity reference views selection arguments in addition to this issue.

colan’s picture

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

brooke_heaton’s picture

Ugh, we need to reroll this for 8.9 :/

gpap’s picture

StatusFileSize
new11.04 KB

[deleted]

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

gpap’s picture

mrinalini9’s picture

StatusFileSize
new11.27 KB

Rerolled patch #47 for 9.1.x, please review.

Status: Needs review » Needs work

The last submitted patch, 56: 2826826-autocomplete_host_entity-56.patch, failed testing. View results

raman.b’s picture

Status: Needs work » Needs review
StatusFileSize
new11.27 KB
new899 bytes

This should resolve the failed test case from #56

hchonov’s picture

  1. +++ b/core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php
    @@ -173,6 +173,12 @@ public static function processEntityAutocomplete(array &$element, FormStateInter
    +      $element['#autocomplete_query_parameters']['host_entity_type'] = $selection_settings['entity']->getEntityTypeId();
    +      $element['#autocomplete_query_parameters']['host_entity_id'] = $selection_settings['entity']->id();
    +      unset($selection_settings['entity']);
    
    +++ b/core/modules/system/src/Controller/EntityAutocompleteController.php
    @@ -99,6 +99,12 @@ public function handleAutocomplete(Request $request, $target_type, $selection_ha
    +      $host_entity_type = $request->query->get('host_entity_type');
    +      $host_entity_id = $request->query->get('host_entity_id');
    ...
    +        $selection_settings['entity'] = $this->entityTypeManager()->getStorage($host_entity_type)->load($host_entity_id);
    

    Behind the key 'entity' we have the entity loaded from the key 'host_entity_id', which isn't consistent. Let us remove the 'host_' prefix.

  2. +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EntityReferenceAutocompleteWidget.php
    @@ -103,6 +103,10 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
    +    if (!$entity->isNew()) {
    +      $selection_settings['entity'] = $entity;
    

    Why?

  3. +++ b/core/modules/system/tests/modules/entity_reference_selection_test/config/schema/entity_reference_selection_test.schema.yml
    @@ -0,0 +1,3 @@
    +# Schema for the entity reference 'entity_test_all_except_host' selection handler settings.
    

    Please stick to 80 char limit. Also we add an empty line after the comment.

  4. +++ b/core/modules/system/tests/modules/entity_reference_selection_test/entity_reference_selection_test.info.yml
    @@ -0,0 +1,9 @@
    +name: "Entity Reference Selection plugin test"
    +type: module
    

    Why do we need a new module just for the one selection plugin? Can't we place it in the entity_reference_test module instead?

  5. +++ b/core/tests/Drupal/FunctionalJavascriptTests/EntityReference/EntityReferenceAutocompleteWidgetTest.php
    @@ -150,6 +152,50 @@ public function testEntityReferenceAutocompleteWidget() {
    +   * rendered on, and is available in the autocomplete results AJAX request.
    

    Shouldn't we use an apostrophe for the genetive case here?:

    results => results'

raman.b’s picture

StatusFileSize
new10.66 KB
new8.31 KB

@hchonov, thanks for the review

Addressed all the pointers

hchonov’s picture

  1. +++ b/core/modules/system/tests/modules/entity_reference_test/src/Plugin/EntityReferenceSelection/AllExceptHostEntity.php
    @@ -0,0 +1,40 @@
    + *   entity_types = {"entity_test"},
    ...
    +    if ($entity instanceof EntityTest) {
    

    We do not need those limitations.

  2. +++ b/core/modules/system/tests/modules/entity_reference_test/src/Plugin/EntityReferenceSelection/AllExceptHostEntity.php
    @@ -0,0 +1,40 @@
    +    // The host entity should be the same type as the entity type this plugin
    +    // supports.
    

    It should not. We just need to get active if it is the same.

Other than that it looks good to me.

raman.b’s picture

StatusFileSize
new10.43 KB
new1.68 KB

We just need to get active if it is the same.

Not sure if I understood this bit correctly 🤔

hchonov’s picture

I've meant the previous condition. We should exclude the host entity ID from the query only if its entity type matches the entity type being queried.

dpi’s picture

To aide in testing and reviews, something similar in concept was already committed for Media Library #3038254: Delegate media library access to the "thing" that opened the library

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

rwohleb’s picture

StatusFileSize
new10.34 KB

Modification of patch #62 to apply to D9.3.

rwohleb’s picture

StatusFileSize
new10.29 KB

Slight fix in patch.

ranjith_kumar_k_u’s picture

StatusFileSize
new10.34 KB
new1.48 KB

Fixed CS errors.

sourabhjain’s picture

Status: Needs review » Reviewed & tested by the community

Looks good. Moving to RTBC.

quietone’s picture

Version: 9.4.x-dev » 10.0.x-dev
Status: Reviewed & tested by the community » Needs work
Issue tags: +Bug Smash Initiative, +Needs reroll, +Needs issue summary update

Switched this to 10.0.x because it needs to be applied there first. Patch no longer applies, so adding tag.

The Issue Summary here does not explain the proposed resolution and that needs to be added. Adding tag.

+++ b/core/tests/Drupal/FunctionalJavascriptTests/EntityReference/EntityReferenceAutocompleteWidgetTest.php
@@ -150,6 +157,50 @@ public function testEntityReferenceAutocompleteWidget() {
+    $other = EntityTest::create(['name' => 'dark blue']);
+    $other->save();

This is the only used of $other, can we just not create the variable?

rpayanm made their first commit to this issue’s fork.

rpayanm’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll

Added the patch #70 and the proposed change in #72. Please review.

zarpele’s picture

StatusFileSize
new10.73 KB

Re-roll for 9.3.14

shubham chandra’s picture

StatusFileSize
new8.31 KB

Added patch against #76 in Drupal 10.0.x

Status: Needs review » Needs work

The last submitted patch, 77: 2826826-77.patch, failed testing. View results

bnjmnm’s picture

#77 was an unnecessary reroll that will not receive credit. It's also an incomplete reroll and misses several changes (notice the difference in patch size). Additional work / review should be based on #76, as #77 breaks several things. As I've mentioned to you several times @Shubham Chandra - you can check if a patch truly needs a reroll by clicking "add test/retest" on the most recent patch and applying it to the most recent Drupal version. Drupal getting a new version doesn't necessarily mean a reroll is needed - and an unnecessary reroll that breaks earlier work is especially not needed.

vasike made their first commit to this issue’s fork.

vasike’s picture

Status: Needs work » Needs review

rebased ... and passed ... so i think we're back to review

For 9. patches ... i think it will be backported after ...

smustgrave’s picture

Status: Needs review » Needs work

Was previously tagged for an issue summary update, if that can be completed please.

Did not review.

flocondetoile’s picture

Issue summary: View changes
flocondetoile’s picture

Status: Needs work » Needs review

Updated the issue summary with the proposed solution, implemented by #80. So back to Need Review.

flocondetoile’s picture

Issue summary: View changes
smustgrave’s picture

Issue tags: -Needs issue summary update +Needs Review Queue Initiative
StatusFileSize
new10.32 KB

Clone of the MR to see if it passes 11.x

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Passed 11.x (committer can remove credit as I didn't do anything but reupload)

Reviewing the MR and changes look good.

Issue summary up to date.

Think it's good for committer review.

berdir’s picture

Left a few comments on the MR.

berdir’s picture

I do like the general approach here with the extra query parameters with just the type and ID, it's pretty much the only option that works and won't cause your key value table to explode over time unlike some of the related and similar issues, so +1 to RTBC once those pretty minor things from my review are addressed.

I do want to point out that the chosen approach does have some limitations, it will not pass along a new entity and it will not be able to pass along field values that have been changed in the current edit form, not directly anyway. So you won't be able to write a selection handler that will filter values based on another field reliably, not unless you save first that is. But the introduction of general support for query parameters should kind of allow to make that work when you alter the form element and add extra query parameters and some ajax refresh magic. A bit hacky, as your plugin will then need to read those again, but it should work.

And last: We should add a change record that documents that new feature I think and maybe also one that mentions that this now works (or a combined one).

vasike’s picture

Add small commit for MR for the request from MR review.

Could we consider the threads there resolved?

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Left some comments in the MR

We also need a change record per comments above.

And did we decide to switch to key value expirable instead?

vasike’s picture

Status: Needs work » Needs review

some updates for MR threads done.

it would be nice if we could close (resolve) some of them ... so we could focus on what's left ...

So NR ... "temporary"

smustgrave’s picture

Status: Needs review » Needs work

@vasike can you update the MR for 11.x or start a new one.

Also appears to be 1 unanswered thread in the current MR.

Hiding patches

vasike’s picture

Status: Needs work » Needs review

For now, updated the current MR with some Kernel tests.
Let's review ... then, if all good, we could move to the current dev branch - 11.x

smustgrave’s picture

Status: Needs review » Needs work

Threads appear to be resolved. And tests look good. But think it would be good to add a test-only patch, then the updated MR. Hopefully that order doesn't trigger the bot.

vasike’s picture

Version: 10.0.x-dev » 11.x-dev
Status: Needs work » Needs review
StatusFileSize
new14.48 KB

let's try a patch file for 11.x

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Since the MR for 10x was reviewed and feedback addressed. Think that carries over to the 11.x version of the patch.

larowlan’s picture

updating issue credits

  • larowlan committed fedfc75e on 10.1.x
    Issue #2826826 by vasike, dpi, raman.b, rpayanm, jibran, gpap,...

  • larowlan committed 91f59e70 on 11.x
    Issue #2826826 by vasike, dpi, raman.b, rpayanm, jibran, gpap,...
larowlan’s picture

Version: 11.x-dev » 10.1.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 91f59e7 and pushed to 11.x. Thanks!

There is a new API here in the sense of a new render array key, but I don't think there is risk of that breaking anything, and this solves a valid bug in terms of missing feature parity for selection plugins depending on widget, so backported this to 10.1.x

Nice work everyone for getting this over the line

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

acbramley’s picture

It seems like there's still a difference between widgets. When using the OptionsWidget, $this->configuration['entity'] contains the current revision being edited. When using the autocomplete widget it's the default revision (because we are loading it by entity id).

Created #3381333: Entity autocomplete widget sends default revision to entity selection handler for that.