Updated: Comment #0

Problem/Motivation

There's core ER field that used for base fields but when entity_reference module is enabled there's no way to use its widget and formatter

Proposed resolution

Properly pass field definition and rename outdated $instance argument.
Provide example if base ER field.

Remaining tasks

Commit patch and proceed with #2107243: Decouple entity reference selection plugins from field definitions

User interface changes

no

API changes

no

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andypost’s picture

Status: Active » Needs review
FileSize
6.24 KB
10.57 KB

Patch with test to make

tstoeckler’s picture

Hit this as well today and came up with the same fix. If this is green, RTBC.

The last submitted patch, 1: 2211553-er-base-1-fail.patch, failed testing.

andypost’s picture

Status: Needs review » Needs work

We still need to load entity display to get "matching" settings properly

andypost’s picture

Status: Needs work » Needs review
FileSize
1008 bytes
10.64 KB

Also loading default display is wrong here, so seems better to pass settings to element as #2107243: Decouple entity reference selection plugins from field definitions

Status: Needs review » Needs work

The last submitted patch, 5: 2211553-er-base-5.patch, failed testing.

andypost’s picture

Base fields does not know their bundle, so filed #2213597: FieldDefinition for base fields should know it's bundle

andypost’s picture

Status: Needs work » Needs review
FileSize
1.52 KB
10.86 KB

There's no other way! Will try to convert entity_test.user_id in next patch

andypost’s picture

FileSize
2.96 KB
10.85 KB

Actually better to pass bundle as argument because base fields could be configured in display.
PS: view mode still default

The last submitted patch, 8: 2211553-er-base-8.patch, failed testing.

andypost’s picture

FileSize
6.11 KB
11.13 KB

Re-use 'entity_test.user_id' field, let's see how many tests are broken

Status: Needs review » Needs work

The last submitted patch, 11: 2211553-er-base-10.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
FileSize
459 bytes
11.58 KB

How many tests would fail if add dependency

Status: Needs review » Needs work

The last submitted patch, 13: 2211553-er-base-13.patch, failed testing.

tstoeckler’s picture

Awesome work, @andypost!!!
I personally think that per #13 this is in fact a bug.

andypost’s picture

Assigned: Unassigned » Berdir

Not sure, seems all fail failed tests assumes that user_id is string so input accepts integer UID.
Let's get @Berdir's opinion on that change... seems a lot of tests should be fixed.
Maybe better to leave 'entity_test' as is and re-use #9

Berdir’s picture

Assigned: Berdir » Unassigned

Yeah, the dependency on entity_reference is unfortunate and yes, using the widget would require to change all those to username (id).

It just seems very weird to add faked field definitions to the EntityTestBaseFieldDisplay class.

Maybe as a middle thing, we can alter user_id and add the widget there and test with that in that test?

andypost’s picture

Status: Needs work » Needs review
FileSize
3.82 KB
10.49 KB

So let's alter field definition exactly for this test

Berdir’s picture

Issue summary: View changes
  1. +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutocompleteTest.php
    @@ -130,6 +132,30 @@ protected function getAutocompleteResult($type, $input) {
    +    //entity_test_create_bundle('test_bundle');
    

    left-over?

  2. +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutocompleteTest.php
    @@ -130,6 +132,30 @@ protected function getAutocompleteResult($type, $input) {
    +
    +    $request = Request::create('entity_reference/autocomplete/single/user_id/entity_test/entity_test/NULL');
    +    $request->query->set('q', 'auto');
    +
    +    $entity_reference_controller = EntityReferenceController::create($this->container);
    +    $result = $entity_reference_controller->handleAutocomplete($request, 'single', 'user_id', 'entity_test', 'entity_test', 'NULL')->getContent();
    +
    

    While we're adding quasi-unit test coverage for this, can we also test some of the error handling in there? like trying to pass in a non-existing field and verifiy it throws an exception?

This looks great. But parts of it are based on my ideas/suggestions, a 1+ from someone else would be nice before I RTBC it.

andypost’s picture

FileSize
1.9 KB
6.42 KB
11.03 KB

1) fixed
2) added test for exception

Supposing this is a bug there's "fail" patch to show that bug fixed

tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

Looks great to me!

One super minor nitpick, but it doesn't hurt anyone so RTBC.

+++ b/core/modules/entity_reference/tests/modules/entity_reference_test/entity_reference_test.module
@@ -4,3 +4,21 @@
+      ->setDisplayConfigurable('form', TRUE);

AFAIK this is not even necessary, setDisplayOptions() should suffice, I think.

The last submitted patch, 20: 2211553-er-base-20-fail.patch, failed testing.

andypost’s picture

setDisplayConfigurable() is need otherwise no settings would be written to display

andypost’s picture

andypost’s picture

Category: Task » Bug report
Priority: Normal » Major
Issue summary: View changes
FileSize
10.97 KB

Suppose absence of this ability is a bug because there's base fields in core but autocomplete broken

PS: re-roll after #2204143: Remove deprecated drupal_explode_tags() and drupal_implode_tags()

andypost’s picture

Issue summary: View changes
Issue tags: +alpha target

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 25: 2211553-er-base-25.patch, failed testing.

andypost’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
10.69 KB

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 28: 2211553-er-base-28.patch, failed testing.

andypost’s picture

Status: Needs work » Reviewed & tested by the community
webchick’s picture

Status: Reviewed & tested by the community » Fixed

This looks like a good clean-up. I asked berdir and there's not really a way to manually test this in the UI, but the test coverage looks good.

Committed and pushed to 8.x. Thanks!

  • Commit d38a69e on 8.x by webchick:
    Issue #2211553 by andypost, Berdir: Allow usage of entity_reference...
andypost’s picture

Status: Fixed » Closed (fixed)

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