I can't get this work with field collection, especially not with the relation add field widget.
To reproduce:
0. standard drupal installation
1. Add directed relation between page (source) and article (destination)
2. Add relation-add field to page and article content types
3. Create some nodes (i.e. with devel_generate module: drush genc 20 0)
4. Edit a node, Relation could be added, works well so far
5. Add a field collection to the page content type
6. Add a text field to the field-collection and a relation add field (optionally)
7. Change relation type and add field-collection to the source bundles (beside article in 1).
8. Edit Article, in the relation field you can enter a page, but it won't get saved as relation
9. Edit the page you wanted to add a relation to in step 8: Relation-add autocomplete is not working; but in the field-collections relation-add field you can add one (try the article from 8). Save the node. The relation between field-collection and article is saved.
10. Back to the article from 8, the relation added in 9 don't show up, but after saving it is still in database and in the page from 9.
Using the relation add block, step 8 is working and crates the relation. In step 9 I still can't enter anything in the autocomplete field.
Using the not so user friendly "Relation Entity Collector block" from the relation module, everything works well.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | fix-issue-with-incorrect-reverse-detection-2531668-10.patch | 612 bytes | nagy.balint |
| #4 | Screen Shot 2015-07-12 at 18.56.35.png | 46.15 KB | osopolar |
| #4 | relation-add-fix-issue-with-incorrect-reverse-detection-2531668-4.patch | 1.46 KB | osopolar |
Comments
Comment #1
osopolarComment #2
nagy.balint commentedSeems like this is a display issue, as the relations are actually added.
at
Incorrectly classifies the relation as reverse, and then
|| ($relation_reverse && in_array($relation->relation_type . ':reverse', $type_settings))is FALSE, so none of the items gets added on display.
Comment #3
nagy.balint commentedSeems like this is an issue from #2429709: Entities with Same ID don't appear.
The reverse detection got "reversed" :)
Patch attached.
Comment #4
osopolarThanks for your fast reply. This may fix a different problem as the one I described above, or may be related, but don't fix the one related to field collection.
@nagy.balint: Where you able to reproduce the problem with field collection? After applying the patch I edited the relation and added on the left side (source) everything except the field collection stuff, on the right side (destination) only article. Editing the article and adding a relation is working. After that I also added the field collection stuff to the left (source) side (without changing anything in the relation_add field settings). Editing the article again but now the relation add field is not working anymore.
I found one thing in relation_add_autocomplete(): It's "giving up" to much, when it could not find the label field for an entity. It should still check for the other allowed entity types, use continue instead of break. Field collections don't have labels, we still could search for field-collection-item id (this is not working yet).
I attached a patch, but I haven't tested much.
Comment #5
osopolarNot sure, if this change is necessary:
Comment #6
nagy.balint commentedHmm, for me with my patch the field collection worked. But I can check again.
In my relation type the field collection item was the source and the other content type the target.
Comment #7
osopolar@nagy.balint: Your test differs from what I described to reproduce the issue. I recommend to set up a clean drupal installation to reproduce. The issue appeared while I wanted to add a relation between article node and page node (not from or to a field collection).
Comment #8
nagy.balint commentedWell, the task is about field collection.
But for me both works. I guess the relation type is different.
Comment #9
nagy.balint commentedThen this should fix the autocomplete issue.
However to fix the label issue its not so easy, maybe this issue could be continued? #1617792: Support for entityreference / setting the entity label patch #17, because querying the entity id is not the best when you want to actually reference a field collection item, and without an actual label field in the database the query will not be able to match on it, also we cannot query the host entity as the host entity can be anything. (maybe only if we make an exception list and say that okay it will work for nodes and such but not for everything)
Comment #10
nagy.balint commentedThe reverse detection is now committed in #2429709: Entities with Same ID don't appear.
So removing that from the patch.
Comment #11
osopolarThanks, this works well.
If you haven't reproduced the issue exactly the same way I described above it could have different results - or maybe I have done something different. The main problem was the break in the foreach-loop. If the bundle you want to reference passed already before the break, you couldn't see any difference, but if not, the auto-complete wouldn't search for that bundle. Therefore issue is related to field collection but adding field-collection disabled the referencing of node bundles.
Anyway the patch fixes this for me.
Comment #13
nagy.balint commentedThanks, Committed.