It would be nice if relation entities could be sorted from the entity form. When I have a directional relationship from A to B, I would like to sort all references to B on the form of entity A. I think this can be accomplished using an integer field on the entity type and some javascript to turn the Relation Select form into a Draggable table.
This integer column can then be used in Views to sort the relation entities.
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | relation_select.png | 32.93 KB | gilles_c |
| #24 | relation_select-sortable-1664502-24.patch | 1.31 KB | trrroy |
| #23 | relation_select-sortable-1664502-23.patch | 1.27 KB | trrroy |
| #22 | relation_select-sortable-1664502-22.patch | 1.69 KB | trrroy |
| #20 | relation_select-sortable-1664502-20.patch | 35.27 KB | steveoliver |
Comments
Comment #1
steveoliver commentedJorrit,
Are you talking about making sortable the instances of a Relation Select field on an entity edit page?
-Steve
Comment #2
Jorrit commentedI haven't used the Relation module long enough to know what exactly you mean by "instance of a Relation Select field" but what I want is to have sortability like the Entity Reference widget. So if I add three relate three (directional) relations to a node, I can drag them in the right order. The order would then be saved in an integer field. Perhaps I can try to make something later this week. The point is, for a project I need sortable relations but also metadata to be specified for a relation. I don't want to end up using Entity Reference for part of the relations and Relation for the others.
Comment #3
steveoliver commentedIf a relation field accepts multiple relations, those 'instances' are what I'm referring to, which I think need to be sortable.
Wouldn't "metadata to be specified for a relation" be actual fields on the relation(s)? See #1645534: Add entity fields to relation select field widget.
And would the field instance delta (int) be enough for your needs?
Comment #4
Jorrit commentedThat is exactly what I meant: I need the Relation module because of its fieldability. If I did not need fieldability, I could use Entity Reference, because that module allows sorting out of the box.
A delta would be enough, but it would be nice to have a draggable interface on top of that. As I said, I'll try to make something this week. Draggable sorting is something that Drupal already supports, I think it is just a question of adding it to the widget. I hope I can make something that is good enough to be added to this module.
Comment #5
steveoliver commentedOK, so we're at the same place then. Let's make this happen.
I think theme_menu_overview_form will be a helpful example to help us implement Drupal's tabledrag.
Comment #6
Jorrit commentedQuick update: it is more work that I expected. I am currently working on making it as a separate widget that can be activated for the Relation select field type. I am not going to support scenarios other than arity = 2, so people with arity != 2 can use the normal widget. In this way, the new widget can even be placed in an entirely separate module. I only need to work on saving the values back to the database and then it should be finished.
Comment #7
steveoliver commentedRegarding the two things that could be sorted:
1. Relation Select field instances.
2. Relation Select relation endpoints.
You can see both pointed out by the blue brackets in this image. The red rectangles are relation fields.
Does this make sense? If so, which are you referring to: (1), (2), or both? I'm thinking both.
Comment #8
steveoliver commentedAfter re-reading everything I see that you are talking about (1), field instances, and are ignoring the use case of (2), endpoints. While one can easily sort more than one Relation Select endpoint by removing and re-adding endpoints in order, It seems reasonable to support endpoint as well as instance ordering as drupal_add_tabledrag() or similar might work for both. I haven't implemented tabledrag or any of this sorting before. Do you have any ideas or experience with this?
Comment #9
Jorrit commentedI am now working on situation (1) which stores the sorting to a weight field. I have not yet looked at (2) because in the UI that I make there is no good way of doing this. I'll try to show it to you soon so you can get an idea.
Comment #10
steveoliver commentedJorrit, are you using any core UI such as tabledrag or similar?
Comment #11
Jorrit commentedYes. I'll post a patch and some screenshots soon.
Comment #12
Jorrit commentedHere you go, I hope you like it.
Comment #13
Jorrit commentedSmall update: EFQ views were not working.
Comment #14
Jorrit commentedSlighly larger update: fixed several errors/notices when adding fields and with fields that have a non-infinite cardinality.
Comment #15
Jorrit commentedForgot the file ...
Comment #16
Jorrit commentedMore updates: fix for the edit button.
Comment #17
steveoliver commentedJorrit,
I've had only a small chance to check out your patch. I have a few notes. First:
One thing that keeps confusing me is why we need an additional 'weight' field on the relation entity. Why can't we just use field delta?
Comment #18
Jorrit commentedWhen I look at the schema of the field table, I only see fields that relate to the entity to which the field is added:
entity_type, bundle, deleted, entity_id, revision_id, language, delta
I can of course modify the delta field, but I don't see how this affects relation instances. I need something that I can sort on in views.
Comment #19
steveoliver commentedI think you are working on a use case that I don't quite grok. In what you seem to be accomplishing here, it appears that you want to essentially adjust the weights of relation field instances relative to the entity on which they are attached (i.e delta) ....AND you want these weights to be relevant in the global context of your site. In other words: It seems you are trying to manage your relations as they are referenced as instances of Relation Select fields at the same time that you are trying to manage your relations among themselves (globally -- hence, field delta does not help you)...
Relation Select field instances are not the same as relations.
Relation Select field instances create and reference relations.
Each relation instance has two contexts:
1. On its own -- it relates endpoints and has fields. It is identified by a relation id.
2. On an endpoint -- the current entity is an endpoint. The relation instance connects this entity with other endpoints.
Each Relation Select field instance has one context:
1. On an endpoint -- the current entity is an endpoint. The field instance may be one of many, in which case, as a field instance, it has a delta.
What you are wanting to do is provide an integer that functions as both the delta to each relation field instance AND a value that can (supposedly) be useful in the context outside of an endpoint(s).
Is this the understanding I should have of what you want to accomplish?
Comment #20
steveoliver commentedOK, Jorrit, I know we've had different use cases around this issue, but I'm going to go ahead with implementing sortable endpoints and instances *without* the weight field -- just using field delta. I know from our conversations that you're working on a separate module to do what you want to do. We'll see how it goes. Here's a patch that I know doesn't work, but starts down the path.
TODOs I can see at the moment:
1. Move sorting from instances to endpoints (that's most important to me at the moment).
2. Don't rely on weight field; use delta.
3. Support any arity
4. Rename widget or just integrate into stock RS widget.
NOTES on this patch:
1. 'theme callback' => 'ajax_base_page_theme', relation_select_field_is_empty() and a couple other things should be in other issues/patches.
So here's the patch...
Comment #21
steveoliver commentedWell I'll be damned, there *was* sortable endpoints, apparently. I noticed in https://vimeo.com/30394905 around 8:00m that endpoints seems to be sortable. Forget the above patch and let's get the old feature fixed. Tagging as a regression. Marking Bug.
Comment #22
trrroy commentedThe value for 'max arity' when set to 'infinity' was correctly set to '0' but the test for setting the item list as sortable was failing in that case since it was testing for >2.
Comment #23
trrroy commentedHere's the same patch without the extra garbage.
Comment #24
trrroy commentedand again
Comment #25
steveoliver commentedCleaned up and committed to f91ec66. Thanks, trrroy.
Comment #27
gilles_c commentedIt seems that we still can't order the relation.
I've create a relation between node with unlimited items, but I can't drag the item & change order.
Comment #28
nwom commentedSetting back to fixed since another issue exists that has a patch regarding sortable endpoints.: #1826538: Cannot sort endpoints before saving
Comment #29
nwom commented