Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Updated: Comment #0
Problem/Motivation
EntityReferenceItem redirects magic ->value calls to ->target_id, which is obscure as there is no value property on entity reference items.
Proposed resolution
Remove that magic redirect.
Remaining tasks
Write a patch that either converts $reference->value calls either to proper domain methods of the particular entity object or to $reference->target_id calls for configurable fields.
User interface changes
none.
API changes
Entity reference items cannot be addressed with ->value anymore.
Comment | File | Size | Author |
---|---|---|---|
#22 | 2188075-psr4-reroll.patch | 6.28 KB | xjm |
#15 | interdiff.txt | 5.49 KB | amateescu |
#15 | entity-reference-item-value-2188075-15.patch | 6.72 KB | amateescu |
#11 | entity-reference-item-value-2188075-10-interdiff.txt | 699 bytes | Berdir |
#11 | entity-reference-item-value-2188075-10.patch | 3.06 KB | Berdir |
Comments
Comment #1
BerdirLet's see what happens then :)
Comment #3
BerdirThis should work better, properly checking for the existence of a field.
Comment #5
BerdirOk, comment explodes, because entity_id is (an incorrectly hardcoded to node) entity reference field but used with ->value all over the place.
Let's wait for #2028025: Expand CommentInterface to provide methods
Comment #6
Berdir3: entity-reference-item-value-2188075-3.patch queued for re-testing.
Comment #8
BerdirRe-roll.
Comment #10
BerdirAPI's changed :)
And I didn't mean to set to RTBC, obviously.
Comment #11
BerdirAnd now forgot the patch. #notmyday :p
Comment #13
BerdirPostponing on #2267753: ContentEntityDatabaseStorage::mapToStorageRecord hard-codes $entity->$name->value
Comment #14
yched CreditAttribution: yched commentedOh, yes yes yes please
Comment #15
amateescu CreditAttribution: amateescu commentedAfter #2267753: ContentEntityDatabaseStorage::mapToStorageRecord hard-codes $entity->$name->value is committed (again), this patch should be green :)
Comment #16
amateescu CreditAttribution: amateescu commentedComment #17
BerdirGreat.
The test fixes show the impact of this change and I think this helps to make clear that ->value is *not* a standard/universal thing that always exists, it's just a common pattern among many single-value field types or field types with that + some additional support properties.
While it might confuse developers in the first moment, I think it will help to understand this, the fact that ->value so far magically worked despite not being defined anywhere so far did not.
Setting to RTBC, I worked on the initial patch but the only things left that I "wrote" are the removed overridden get()/set methods, so I think that's OK.
It's kind of an API change, even though it never really was an API, just a workaround that was added when the main property concept didn't exist yet.
Comment #18
yched CreditAttribution: yched commentedRight. +1 for the exact reasons @berdir stated in #17.
Comment #20
Berdir15: entity-reference-item-value-2188075-15.patch queued for re-testing.
Comment #21
BerdirWas a testbot problem.
Comment #22
xjmReroll for #2247991: [May 27] Move all module code from …/lib/Drupal/… to …/src/… for PSR-4.
Comment #23
catchCommitted/pushed to 8.x, thanks!