Problem/Motivation
It is not possible to add relationships to a view based on entity reference fields, this is needed to use the referenced entity for fields/filters/sorts.
Will also become useful if we start to generalize this into a generic views data generation for entities, as we will also need it for things like the node -> author base field entity reference.
This is also functionality you currently get with the contrib entityreference module.
Proposed resolution
Add the necessary views data integration.
Remaining tasks
User interface changes
Adds new relationship options to the views UI.
API changes
Comments
Comment #1
dawehnerJust tracking some work, because #1906794: Using a relationship in the UI fails completly blocks this issue.
Comment #2
amateescu commented'_target_id' ;)
Comment #3
amateescu commentedAlso moving to the new component.
Comment #4
dawehnerJust tracking some more work.
Comment #5
dawehnerJust a rerole.
Comment #7
nicxvan commentedShouldn't this be a beta blocker? I believe this is essential functionality for entity reference. Will this be fixed before beta?
Comment #8
stephencross commentedI agree with nicxvan about this being a beta blocker. The value of having entity relationships is core is joining those relationships in views (now in core).
Comment #9
berdirThis simply missing functionality that can be easily added at any point, it dosn't involve storage or API's, so there's no need for this to block beta.
If you want to see this moving forward, try it out, give feedback and try to fix those failing tests.
Comment #10
Sifro commentedI'll give this one a try
Comment #11
Sifro commentedhere is a small reroll.. it's my first attempt at contributing something, let's see what happens with the testbot
Comment #12
Sifro commentedOk, uploading interdiff with patch.
Comment #14
Sifro commentedAny chances that the exception is related to https://drupal.org/node/1783692 ?
Comment #15
Sifro commentedComment #16
Sifro commentedoh please delete me.
Comment #19
roysegall commentedJoining this issue. I'll see how i can help this.
Comment #20
Sifro commentedI'll bit a bit busy for the next 10 days, so if in the meanwhile someone wants to help, it'll defintiely speed up the process.
I've made some progress since the last patch i posted, but they aren't really ready for posting.
IMO, the next thing to do is to convert the
field_create_field()function ( called in EntityReferenceRelationshipTest::setUp() ) to use the new entity API.After some searches, it looks like we need to use the function
entity_create('field_config', $field)->save();Comment #21
roysegall commented@Sifro - if you made any progress i think you should post it any way. This still a progress you made :)
Comment #22
Sifro commentedCan't finish it in the short term because of unexpected workload... if someone wants to take this, feel free to do it.
@RoySegall: it's not worth it to post an interdiff with the latest minor changes I've made, as they don't really fix any failures.
However, this is what I was working on: in EntityReferenceRelationshipTest::setUp()....
became
and...
became...
For some reasons, it still doesn't work, and couldn't figure out why :(
Comment #23
berdirYeah, this was pretty old :)
Tests is now passing again for me, might still need more changes...
Comment #24
berdirAnd the actual patch...
Comment #25
tim.plunkettNothing but nitpicks, this looks good.
Also, the issue summary doesn't exist.
\Drupal
Missing comma
Missing ()
{@inheritdoc}
Comment #26
berdirThanks for the review, fixed that and also made it a unit/kerneltest, 9s => 2s.
Comment #27
damiankloip commentedweird that one is entity_0 and the others are entity. I know the first one is used to get referenced. Maybe we can call it $referenced_entity?
You can use Views::viewsData()->get() is you like.
'Check an actual test view' ?
maybe getFieldValue() would be better here? or just checking the result data directly?
Comment #28
berdir1. Good point, found the _0 weird too when I first re-rolled this, renamed to $referenced_entity. also removed the @todo, I commented it out and it's no longer an issue but forgot to actually remove it and the @todo.
2. Updated.
3. Yeah, fixed.
4. getFieldValue() sounds nice, but it's a protected method. And not sure that I should be accessing the data result directly?
Comment #29
damiankloip commentedOh yeah. Forgot that is a protected method.. :)
What's wrong with just looking at data directly? The tests are about the relationship data, not style plugins or field rendering.
Comment #30
berdirUhm, just tried it out and then forgot to change it back..
If you want to check the result data directly, please update the patch, I'm not exactly sure how to do it properly :)
Comment #32
damiankloip commentedok :) I just mean something like this. I added a couple of comments too.
Comment #33
damiankloip commentedSome small quibbles.
Comment #34
berdirUpdated issue summary, not much to write I think?
Comment #35
damiankloip commentedComment #36
tim.plunkettNice tests. I think the improvements since #25 are good.
Comment #37
tstoecklerThese are very bad variable names. If we do need both variables the former should be called $target_entity_type_id. Or it should be called $target_type_id and the latter should be called $target_type.
As FieldConfig implements EntityInterface speaking of a "field entity type" is very, very confusing. Let's call this the "entity type with the entity reference field" vs. the "entity type that is referenced by the field".
Seems a bit inconsistent to use a single underscore and a double underscore as separators in a single string?!
$args should be used here as well.
Comment #49
jibranNice try.
Comment #50
damiankloip commentedok, I renamed the first variable to $target_entity_type_id - which I think is totally accurate. That's what it is. $target_entity_type is now fine IMO. Updated doc comments, replaced $arg usage, and used double underscore to separate the reverse pseudo table name. A couple of other small tweaks like the title and description of the tests. Since we are really just testing the data integration and not a new handler.
Two interdiffs because I forgot to include the tests changes and was too lazy to roll back into one... sorry! :p
Comment #51
tstoecklerAwesome, thanks a lot. Was RTBC before, so marking RTBC again.
Comment #53
damiankloip commented50: 1906806-50.patch queued for re-testing.
Comment #54
damiankloip commentedComment #55
alexpottCommitted 7ba018f and pushed to 8.x. Thanks!
Comment #57
xem8vfdh commentedAm I missing something? I am still unable to create a backward reference (formerly referred to in D7 as "A bridge to the Content entity that is referenced via *field_machine_name*").
I've got a content type Artist and another content type Album, which has a Content Reference field called "artist". In my Album view, I cannot find a backward relationship ("bridge") that points to the related Artist entity to access the Artist fields. Is there some special configuration I am missing, perhaps?
Thanks in advance.
EDIT: There is no "bridge" option. When creating the relationship, I was looking for a "relate" option, but it turns out that I should have been looking for a "reference" option. Once I searched for "refer" when creating a new relationship, I saw an option for "Content referenced from field_album_artist", which allowed me to access the necessary fields.