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

Comments

andypost’s picture

Status:Active» Needs review
StatusFileSize
new6.24 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 65,092 pass(es), 0 fail(s), and 1 exception(s).
[ View ]
new10.57 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 65,090 pass(es).
[ View ]

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
StatusFileSize
new1008 bytes
new10.64 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 65,057 pass(es), 0 fail(s), and 1 exception(s).
[ View ]

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
StatusFileSize
new1.52 KB
new10.86 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 65,243 pass(es), 0 fail(s), and 1 exception(s).
[ View ]

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

andypost’s picture

StatusFileSize
new2.96 KB
new10.85 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 65,241 pass(es).
[ View ]

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

StatusFileSize
new6.11 KB
new11.13 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 63,759 pass(es), 810 fail(s), and 212 exception(s).
[ View ]

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
StatusFileSize
new459 bytes
new11.58 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 64,242 pass(es), 213 fail(s), and 60 exception(s).
[ View ]

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
StatusFileSize
new3.82 KB
new10.49 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 66,346 pass(es).
[ View ]

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

StatusFileSize
new1.9 KB
new6.42 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] 66,409 pass(es), 0 fail(s), and 1 exception(s).
[ View ]
new11.03 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 66,412 pass(es).
[ View ]

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

StatusFileSize
new10.97 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 66,353 pass(es).
[ View ]
andypost’s picture

Category:Task» Bug report
Priority:Normal» Major
Issue summary:View changes
StatusFileSize
new10.97 KB
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] Unable to apply patch 2211553-er-base-25.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

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
StatusFileSize
new10.69 KB
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 66,645 pass(es).
[ View ]

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.