Closed (fixed)
Project:
Dynamic Entity Reference
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
9 Aug 2015 at 19:13 UTC
Updated:
27 Oct 2015 at 12:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
dpiComment #3
dpiIdeally hook_field_views_data should be merged into hook_views_data to reduce duplicate code.
Comment #4
jibranFor ER core adds data in
EntityViewsData::processViewsDataForEntityReference()see #1740492: Implement a default entity views data handler. Use ofhook_views_dataseems wrong because it adds new data where as we are altering existing data so maybehook_views_data_alter. @dawehner what do you suggest?Comment #5
dpiI think we should be using hook_views_data, we're creating a whole collection of new fake fields. If it was just one then we could use the existing column field.
Comment #6
dpiThis one checks that both entity types are SQL and removes debug junk.
Comment #7
dpiComment #8
dpiThis patch refactors both hooks into one.
Comment #10
dpiComment #13
dawehnerComment #14
jibranUpdated summary.
Comment #15
dpiTest shouldn't pass until #2553831: getTargetTypes has expectations that are not being met is committed.
Comment #18
jibranLet's not combine both the hooks. We should keep
dynamic_entity_reference_field_views_data()because it is the proper way and I think we can usedynamic_entity_reference_views_data()for base fields so that other modules can change that inhook_views_data_alter(). Note thatdynamic_entity_reference_views_data()is a temporary fix till we have a proper api after #2337515: Allow @FieldType to customize views data.I have worked on this over the weekend. I used the patch from #6. I have setup a test module with basefields found some nasty edge cases. I'll write some tests later this week.
Comment #20
jibranRe: #15 Patch looks good. Can you move base field relationships to
hook_views_dataas per #18? I can add my tests in #2542274: Write tests for DER field as basefield on an entity.Does it work properly when a base field has a dedicated table?
Comment #21
dpiI have split them back into separate hooks.
I have a DER base field with unlimited cardinality (which results in dedicated table) in Courier's template collection entity. It works as expected.
Comment #22
dpiOne day I'll remember
Comment #23
dpiI didn't properly test back references to base fields with multiple cardinality. This fixes it.
In addition, relationships are no longer created to entities that do not support views.
Comment #24
jibranLet's revert all the changes to this hook.
Comment #25
dpiNo changes, only revert to fields hook per #24.
Can we do the changes in a different issue (out of scope)? Or is there something wrong with the changes?
Comment #26
dpiOops deleted imports.
Removed $table
foreach.Comment #27
jibranNothing wrong with the changes. I quiet like the changes. Let's move them to follow up and let's also fix them in core for ER field as well.
Comment #28
jibranAdded relationship data test for single field. Made some changes because of tests. Update docs.
Needs to add actual view to verify the relationship.
Unable to make the base field multivalue but is behaving as a multi field anyway.
Needs to relationship data test for multivalue field.
Needs to add actual view to verify the relationship.
Comment #29
jibran@plach can I do this in test? Or is there some easy way to update base field definition.
dynamic_entity_reference_entity_testadds a base field nameddynamic_referenceswith 1 cardinality. For testSingleBaseFieldRelationship test that works fine but I have to make it anFieldStorageDefinitionInterface::CARDINALITY_UNLIMITEDfor second testtestMultiBaseFieldRelationship. I tried above code in the test from https://www.drupal.org/node/2554097 but it gave exception.I set cardinality to 1 but how come I can set two values for a field and it passes? Is there something wrong with der?
Comment #30
jibranHere is uncommented version of
testMultiBaseFieldRelationshipThis patch will fail with exception.Comment #32
jibranOk I found the way around #29.1 so unping @plach. But #29.2 is still an issue. Anyways this patch is green. Remaining thing is to check these with actual views.
Comment #33
jibranWhy can't I use state here? Core tests use it all over the place. Any suggestions!
Comment #34
jibranHere are the tests for basefield view tests with 1 cardinality, found a bug in views data and fixed it. Remaining tasks are doc fixes and cardinality > 1 testing with view.
Comment #35
jibranAs it turns out views integration for multi value basefields is broken #2477899: Multiple valued Base fields won't work in Views. We can't really write views tests for multi values der basefield not until we add relationship ourselves which seems hacky and can be moved to follow up. Only thing remaining here is write tests for entity_test_mul der basefield. I'll look at it later tonight.
Comment #36
jibran@todo
Comment #37
jibranYay!!! found another issue in DERBaseFieldViewsData. Tests++
Added a do-not-test patch without any of the test codes.
Fixed views for multi value basefield.
@todo
Add tests for multi value basefield views.
Comment #40
jibranEverything is done here. This is ready for reviews.
Comment #41
dpiLooks ready to go.
I assume this comment is for the intersect operation:
Something like
$relationship
Why not just merge the array directly with
$data[$target_table][$psuedo_field]['relationship']instead of creating a variable?And finally
Do you want to change the relationship ID? ($psuedo_fieldassignments) to prevent potential collisions with core.Solution: Add a prefix like "der_". We shouldnt be changing ID's after this is committed as it will break existing views.If the plan is to remove the code later. Then we must ensure the ID is identical, and core provides identical functionality.
Comment #43
naitik945 commentedIn general, all lines of code should not be longer than 80 characters.
https://www.drupal.org/coding-standards#linelength
In general, all lines of code should not be longer than 80 characters.
https://www.drupal.org/coding-standards#linelength
In general, all lines of code should not be longer than 80 characters.
https://www.drupal.org/coding-standards#linelength
Comment #44
dpiWTF
Spam deleted.
Comment #45
jibranFixed #41, #42 and #43.
The ID is identical that is why I was able to create views from gui.
Core is not providing any relationship. Core doesn't even know that relationship exists so no collision possible.
Comment #46
dpiYep, all good, I struck the text since I saw
$field_nameis used in the ID. I wrongly assumed it was concatenating origin and target etids.Looks good to go.
Comment #47
jibranUpdated setup function logic to accommodate #2542274: Write tests for DER field as basefield on an entity.
Comment #48
jibranAnd interdiff.
Comment #49
jibranImprovements from #2542274: Write tests for DER field as basefield on an entity.
Comment #50
dawehnerComment #51
dawehnerThis looks really good, I would say, ship it!
Afaik you could just use
\Drupal\Core\Entity\Sql\TableMappingInterface::getFieldTableNamehere?I know this is probably an unsolved problem, but I just want to rise the problem that you might get translations by this join.
I really like this docs!
Great documentation!
Comment #52
deanflory commentedWhen I attempted to apply provide_views-2548395-47.patch to the latest 7.x dev 2015-Aug-19, there were missing files that the patch would not create on it's own, nor could handle if a blank file of the name it needed was put in the module folder, then there were a bunch of yml files that couldn't complete either.
Notice this is with #47.
Same with #49.
Comment #53
dpiThis is for 8.x
Comment #54
jibranReroll after #2542274: Write tests for DER field as basefield on an entity.
@dawehner thank you so very much for the review. It was totally worth waiting for :).
Comment #56
jibranPushed to 8.x-1.x.
Thank you @dpi for working on the initial patch. Can you please create the followup issue for #24, #25?
Thank you @dawehner for all your help in IRC as well.