Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#28 | 2211553-er-base-28.patch | 10.69 KB | andypost |
Comments
Comment #1
andypostPatch with test to make
Comment #2
tstoecklerHit this as well today and came up with the same fix. If this is green, RTBC.
Comment #4
andypostWe still need to load entity display to get "matching" settings properly
Comment #5
andypostAlso loading default display is wrong here, so seems better to pass settings to element as #2107243: Decouple entity reference selection plugins from field definitions
Comment #7
andypostBase fields does not know their bundle, so filed #2213597: FieldDefinition for base fields should know it's bundle
Comment #8
andypostThere's no other way! Will try to convert
entity_test.user_id
in next patchComment #9
andypostActually better to pass bundle as argument because base fields could be configured in display.
PS: view mode still default
Comment #11
andypostRe-use 'entity_test.user_id' field, let's see how many tests are broken
Comment #13
andypostHow many tests would fail if add dependency
Comment #15
tstoecklerAwesome work, @andypost!!!
I personally think that per #13 this is in fact a bug.
Comment #16
andypostNot 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
Comment #17
BerdirYeah, 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?
Comment #18
andypostSo let's alter field definition exactly for this test
Comment #19
Berdirleft-over?
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.
Comment #20
andypost1) fixed
2) added test for exception
Supposing this is a bug there's "fail" patch to show that bug fixed
Comment #21
tstoecklerLooks great to me!
One super minor nitpick, but it doesn't hurt anyone so RTBC.
AFAIK this is not even necessary, setDisplayOptions() should suffice, I think.
Comment #23
andypostsetDisplayConfigurable()
is need otherwise no settings would be written to displayComment #24
andypostre-roll after #340723: Make modules and installation profiles only require .info.yml files
Comment #25
andypostSuppose 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()
Comment #26
andypostComment #28
andypostRe-roll after #2093173: Remove all calls to drupal_json_decode(), use \Drupal\Component\Utility\Json::decode()
Comment #30
andypostComment #31
webchickThis 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!
Comment #33
andypostFiled follow-up #2226551: Allow usage of "taxonomy_term_reference" field widget and formatter for base fields