* Add Er field to article
* Try to reference another article -- autocomplete JS doesn't seem to be attached to the text field.

#21 2084081-21.patch4.95 KBamateescu
PASSED: [[SimpleTest]]: [MySQL] 59,304 pass(es).
[ View ]
#18 2084081-test-only.patch1.51 KBamateescu
FAILED: [[SimpleTest]]: [MySQL] 59,262 pass(es), 3 fail(s), and 0 exception(s).
[ View ]
#18 2084081-18.patch4.97 KBamateescu
PASSED: [[SimpleTest]]: [MySQL] 59,241 pass(es).
[ View ]
#11 2084081-11.patch3.46 KBamateescu
PASSED: [[SimpleTest]]: [MySQL] 59,288 pass(es).
[ View ]
#11 interdiff.txt792 bytesamateescu
#6 entityautocomplete1.png55.2 KBandymartha
#1 2084081.patch3.42 KBamateescu
PASSED: [[SimpleTest]]: [MySQL] 58,606 pass(es).
[ View ]


Status:Active» Needs review
new3.42 KB
PASSED: [[SimpleTest]]: [MySQL] 58,606 pass(es).
[ View ]

Here's the fix.

Can we write a test for this?

Title:ER Autocomplete doesn't workER autocomplete doesn't work

I couldn't figute out a way to test it.. :/

I couldn't figute out a way to test it.. :/

* Deprecate Taxonomy term field
* Enable entity-reference by default -- then everybody would see it doesn't work :P

Yeah, I wanted to do this for a while: #2084309: Enable Entity reference in the standard profile

new55.2 KB

Hmm, after applying patch 2084081.patch in #1 by amateescu, I haven't noticed any difference. I don't see an AJAX auto-complete when trying to follow the instructions in issue summary (see screenshot).


@andymartha, it still works for me, and I only had to refresh the page after applying the patch. Are you sure you have another article to reference so the autocomplete can return something?

I thought about tests some more and we really don't have a way to test this kind of AJAX stuff, so we have to rely on manual testing here.

Status:Needs review» Reviewed & tested by the community

Works as expected.

+++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php
@@ -74,23 +74,24 @@ public function formElement(FieldInterface $items, $delta, array $element, $lang
     if ($entity && $entity_id = $entity->id()) {

Can we remove the if ($entity) part ?
There is always an $entity, the code calls its ->entityType() & ->bundle() methods a couple lines above.

new792 bytes
new3.46 KB
PASSED: [[SimpleTest]]: [MySQL] 59,288 pass(es).
[ View ]

Sure thing.

Are we sure that we don't want to write a test for that?

I never said I don't want to, just don't know *how* to :)

This kind of tests exists at least in two places, so feel free to spread the word: core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyIndexTidUiTest.php

I'm looking at that test class and all I see is testing an already populated select list, nothing to do with an Ajax autocomplete.


// Ensure the autocomplete input element appears when using the 'textfield'
    // type.
$view = entity_load('view', 'test_filter_taxonomy_index_tid');
$display =& $view->getDisplay('default');
$display['display_options']['filters']['tid']['type'] = 'textfield';
$result = $this->xpath('//input[@id = "edit-options-value-autocomplete"]');
$this->assertEqual((string) $result[0]['value'], url('taxonomy/autocomplete_vid/tags'));

Status:Reviewed & tested by the community» Needs work
Issue tags:+Needs tests


Status:Needs work» Needs review
Issue tags:-Needs tests
new4.97 KB
PASSED: [[SimpleTest]]: [MySQL] 59,241 pass(es).
[ View ]
new1.51 KB
FAILED: [[SimpleTest]]: [MySQL] 59,262 pass(es), 3 fail(s), and 0 exception(s).
[ View ]

Right, I had to pull the latest code because that hunk you pasted was only committed yesterday. And it led me in the right direction because I could see a difference in the html output of the element, the one that works has a 'form-autocomplete' class. Thanks for the pointer :)

  1. +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php
    @@ -17,7 +17,7 @@ class EntityReferenceAutoCreateTest extends WebTestBase {
    -      'name' => 'Entity Reference auto-create',
    +      'name' => 'Entity Reference auto-create and autocomplete UI',

    Wat? You are the maintainer of EntityReference ... but the main reason why I didn't just jumped in was that I could not find a testfile where this fits in :)

  2. +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php
    @@ -76,12 +76,16 @@ function setUp() {
    +   * Tests that the autocomplete input element appears and the creation of a new
    +   * entity.
       public function testAutoCreate() {
         $user1 = $this->drupalCreateUser(array('access content', "create $this->referencing_type content"));
    +    $this->drupalGet('node/add/' . $this->referencing_type);
    +    $this->assertFieldByXPath('//input[@id="edit-test-field-0-target-id" and contains(@class, "form-autocomplete")]', NULL, 'The autocomplete input element appears.');
         $new_title = $this->randomName();

    Maybe at least create a new test method?

And add a few more seconds to the testing time just for those two lines? No way :)

new4.95 KB
PASSED: [[SimpleTest]]: [MySQL] 59,304 pass(es).
[ View ]


Status:Needs review» Needs work

The last submitted patch, 2084081-21.patch, failed testing.

Status:Needs work» Needs review

#21: 2084081-21.patch queued for re-testing.

Status:Needs review» Reviewed & tested by the community

Yeah let's not waste time on the testbot.

#21: 2084081-21.patch queued for re-testing.

Status:Reviewed & tested by the community» Fixed

Committed 75b8c06 and pushed to 8.x. Thanks!

Status:Fixed» Closed (fixed)

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