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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

amateescu’s picture

Status: Active » Needs review
FileSize
3.42 KB

Here's the fix.

aspilicious’s picture

Can we write a test for this?

amateescu’s picture

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

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

amitaibu’s picture

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

amateescu’s picture

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

andymartha’s picture

FileSize
55.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).

entityautocomplete1.png

amateescu’s picture

@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.

amitaibu’s picture

Status: Needs review » Reviewed & tested by the community

Works as expected.

amitaibu’s picture

yched’s picture

+++ 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.

amateescu’s picture

FileSize
792 bytes
3.46 KB

Sure thing.

dawehner’s picture

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

amateescu’s picture

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

dawehner’s picture

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

amateescu’s picture

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.

dawehner’s picture

See

    // 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';
    $view->save();
    $this->drupalGet('admin/structure/views/nojs/config-item/test_filter_taxonomy_index_tid/default/filter/tid');
    $result = $this->xpath('//input[@id = "edit-options-value-autocomplete"]');
    $this->assertEqual((string) $result[0]['value'], url('taxonomy/autocomplete_vid/tags'));
webchick’s picture

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

Yep.

amateescu’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
4.97 KB
1.51 KB

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 :)

dawehner’s picture

  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->drupalLogin($user1);
     
    +    $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?

amateescu’s picture

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

amateescu’s picture

FileSize
4.95 KB

Rerolled.

Status: Needs review » Needs work

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

amateescu’s picture

Status: Needs work » Needs review

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

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Yeah let's not waste time on the testbot.

David Hernández’s picture

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

alexpott’s picture

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.