Closed (won't fix)
Project:
Relation
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
1 Jun 2011 at 13:16 UTC
Updated:
9 Nov 2012 at 06:20 UTC
Jump to comment: Most recent file
Comments
Comment #1
wesnick commentedThis would be very nice. I think it might be useful to provide a sort of relation_field_provider_info hook so custom entities can define their relevant select options function, autocomplete callback function and not have to worry about building FAPI elements.
Comment #2
naught101 commentedchx: Why do we need specific widgets per entity_type? Sorry, you've probably told me this before, I'm obviously having trouble accepting it or something :/ maybe I'll get it if you write it down somewhere where I can come back to it...
It'll still be a dummy field, since we're not gonna be storing data.
Wesnick: I reckon that's stage two. Might need to wait a bit on that one.
Comment #3
dpiBecause there is no guaranteed way to get a label, and there may be better ways to display information about each entity type.
The entity_label method is also horribly inefficient.
Per-entity sounds great. Although Relation should provide core entity support.
Comment #4
30equals commentedso if i'm not mistaken, a widget can't be used on node creation only node editing ? because you need the nid to create a relation ?
i tried using the relation_create function in hook_entity_insert so i have access to the nid, but i noticed that hook_entity_insert get's called twice because relation_create is calling it as well .....?
Comment #5
naught101 commentedCan't you just check that the entity being inserted is a relation? Except then you write off the possibility of creating relations-on-relations during relation creation. Not sure how much that matter, at least for now..
Comment #6
30equals commentedActually no: the second time it get's called $type or $entity->type isn't even availabe...
so if i check if $type is set - and then check which type it is,i'm still getting an error that the second argument for hook_insert_entity isn't passed the second time it gets called...
the relation does get created though, with the error....
isn't there a better way to do this, or maybe i'm missing something..?
Comment #7
naught101 commentedtry !isset($entity->relation_type). ->type is a node-specific thing.
Comment #8
30equals commentedthanx, but the main problem is that the $type argument isn't passed one the second call of hook_entity_insert...
'Warning: Missing argument 2'...
relation.module #444 -- this is in the relation_save function
--> module_invoke_all('entity_insert', $relation);
this one gets executed right after my hook_entity_save where i've put the relation_create function. and relation_save gets called in relation_create.
using releation_create in the hook_entity_insert causes hook_entity_insert to get called again.
so you see, checking on $type or anything like that is useless, the error keeps popping up.
so i figured that maybe there's a more proper way to create a relation on node creation, because obviously this isn't how it's supposed to be...?
Comment #9
naught101 commentedplease update to the latest dev, or preferably, to git, as it makes development work far easier. Relation_save is no-longer called from within relation_create - you have to call
Dunno if that'll fix the problem though..
Comment #10
30equals commentedupdated to the new dev and tried it with your code suggestion... same problem with the double call and argument missing the second time. Gonna take a look at it later to check if i can workaround it.
Comment #11
30equals commentedok, so here's what i did to fix my problem:
in relation.module #518
changed
to
same with the entity_update..
i don't get the errors anymore, but i was wondering if this can have a negative consequence later on ?
Comment #12
30equals commentedadjustments as a patch..
Comment #13
30equals commentedplease ignore the patch as we want other module to hook into the relation_save. naught101 submitted a patch so there's an extra argument passed, and the error doesn't occur anymore.
Comment #14
joachim commented> so if i'm not mistaken, a widget can't be used on node creation only node editing ? because you need the nid to create a relation ?
That's surely not the case. Look at how image_attach used to work on D6 -- that created a relation between the current node and an existing image node, and worked during node creation.
> Because there is no guaranteed way to get a label, and there may be better ways to display information about each entity type.
Doesn't the admin creating the relation field supply the label?
Comment #15
naught101 commented@Joachim: "Doesn't the admin creating the relation field supply the label?"
We're talking about the label for the entities in the autocomplete here, eg. node title, user name, what ever. Some entities (like relations) don't have any label (relation types have a label, but relations themselves don't). You're correct on the other point, as long as the relation creation happens in hook_entity_insert().
Comment #16
joachim commentedRegarding labels, IIRC entity module has a system for getting labels out of entities.
Comment #17
naught101 commentedRelation is not dependant on entityAPI, and we don't want it to be, if we can avoid it. Anyway, for relations, and other entities like it, the only "label" that ANY method will be able to extract is the numerical ID, simply because no other label exists. I think an autocomplete for entities like this would be more than a bit useless.
Comment #18
joachim commented> I think an autocomplete for entities like this would be more than a bit useless.
Not just autocomplete then -- also select lists and checkboxes.
Which means that this module can't be a successor to nodereference.
What are the reasons against depending on EntityAPI?
Comment #19
naught101 commentedcheckboxes? Joachim: you're missing the point. Some entities DO NOT HAVE LABELS. What would you have next to the checkbox? a number?
We would prefer not to depend on any contrib modules.
Comment #20
joachim commentedThe way I see it is this: if this module is intended to be the successor to nodereference and userreference then it needs to provide the ease of use those had. That means checkboxes, select lists, and autocomplete. This is simply a given. If on the other hand it's more an API module, then that's fine too. But then we should probably let http://drupal.org/project/references know to change their project page text.
I'm scratching my head thinking of entities without labels, and just ran a module_invoke_all('entity_info'); to have a look.
I also don't see what is so bad about depending on contrib modules.
Comment #21
georgir commentedif labels are defined for other entity types somehow, relation entities can have labels too - implode the labels of the endpoints with a dash.
Comment #22
naught101 commentedI'd thought about that too, but then what happens if you have a relation between two relations (eg. something like "happened at the same time as"), or a relation between two entities that have numeric labels?
Comment #23
joachim commented> relation entities can have labels too - implode the labels of the endpoints with a dash
Aaah, now I get it. Relation entities don't have labels :D
But I think if a site admin wants to have relations between relations, they should expect things to get complex. Maybe require/allow them to add a label field to the relation type?
Comment #24
naught101 commentedbtw: related to #6: #1042822: Developers need an $entity->entity_type property
Comment #25
dpiShort discussion regarding widgets: https://gist.github.com/1079482
Hopefully this can be realized quickly.
Comment #26
wesnick commentedWould love to follow the short discussion but this pastebin link is not working.
Comment #27
dpiTry again.
Comment #28
chx commentedTagging
Comment #29
clemens.tolboomComment #30
yched commented@chx ; References widgets rely on [node|user]_reference_potential_references(), which in turns rely on specific $field['settings'] properties. Using those widgets for a 'noderef-like but relation-backed' field type *might* work if the 'noderef_based_on_relation' field type replicates the settings of the noderef field type, but that could get a bit ugly...
Maybe some re-engeneering / abstraction of the References widgets could help (let the field type provide a custom 'potential references' callback), but starting new widgets from scratch sounds like it would be less intricated down the road...
(counts as a 'subscribe')
Comment #31
kirkilj commentedIf I'm not tracking the implications of the part of this discussion concerning labels, let me know.
Would these labels be translatable so that multi-language sites can use the local language equivalent and still be choosing the proper end-points and relations? Do any of the options discussed in this issue automatically provide this capability, or would it have to be added explicitly by the Relation module or the developer who uses the Relation module?
Also, as others have asked, why the reticence to use the Entity contrib module, which seems to be one of those modules whose intention appears to be filling in basic missing functionality in the Entity API with basic CRUD capability? If the Entity and Relation modules were both moved into core, would it then address the dependency concern?
Comment #32
klonos...subscribing.
Comment #33
chx commentedPushed some code. Add tests, give feedback, stir, release.
Comment #34
Jackinloadup commentedFirst thanks everyone for all the awesome work!
@chx
I found that the latest code you submitted (97b1955) you added an instance settings to the field that allows selection of relation_type. When using this I noticed that the field formatter didn't respect this. The attached patch fixes this.
Also I tried to use the but nothing I seemed to type in came up with anything.
Comment #35
chx commentedYeah, I realized that but it was already late when I finished :) Do we want the formatter and the widget to use the same relation types? I am not so sure about that. I was considering moving to widget settings rather. And have a separate formatter setting? That's quite a meh isnt it?
Comment #36
naught101 commentedThis is something I considered before: I think it would make sense to have a field-level setting that allows you to either blacklist or whitelist relation types that can be included in the dummy_field. Then the widget will only appear on entities that are included in one of those relations, and same for the formatter. But that's probably a separate issue. But I don't really see why there would be a reason to restrict relation types on a field instance level, nor why there would be different options for formatter and widget.
Comment #37
yched commentedFWIW : defining scope at the field level, so that all shared instances have the same predictable set of possible values, is more inline with the way 'reference' fields (or fields with allowed values) generally work.
OTOH, this is generally useful for views integration (being able to present relevant options for filter, args, relationships...). Maybe this is less true for Relation's specific views integration ?
Comment #38
alanom commentedBack to the not entirely resolved question about labels, assuming that relations are the only entities without labels as implied above, surely you can capture everything with a format [source endpoint][directional relation type label][target endpoint]
(adding in 'and's and additional endpoints where needed for multiple arity).
Example:
Relation type 'letting agent' ('is agent to', 'agent is'): Node: agent ->- Relation: renting appartment
Relation type 'account supervisor' ('supervises', 'supervised by'): Node: manager->- Relation: letting agent
Source label: Johnson family
Target label: 100 First Street
Relation label (for admin): Johnson family rents 100 First Street
Source label: Dave Meadows
Target label: Johnson family rents 100 First Street
Relation label (for admin): Dave Meadows is letting agent to Johnson family rents 100 First Street
Source label: Bill Riley
Target label: Dave Meadows is agent to Johnson family rents 100 First Street
Relation label (for admin): Bill Riley supervises Dave Meadows is letting agent to Johnson family rents 100 First Street
It's not good grammar and it's a complicated label, sure. You'd only display this on the admin pages. But look at it: it describes a relation on a relation on a relation. It's a complex, abstract entity to understand, yet any user can understand exactly what it represents and how it's structured just from glancing at the label.
"What's that? Bill Riley is no longer overseeing Dave's work on the Johnson family account in 100 First Street? Okay, I'll delete the relation... where is it... there it is, that's the one to delete. Done. Easy."
The only point at which this breaks is if you somehow get a loop, where it's possible for there to be a chain of relations all of which relate to relations, and this then loops back on itself. But that's not possible - a loop would require a relation to have an endpoint that didn't exist when the relation was created.
Comment #39
jtbayly commentedsubscribe
Comment #40
naught101 commentedRelations do kind of already have label: just "Relation ###", where ### is the rid. But that's not enough, the label also has to be stored in the DB for entityfieldQuery to be able to read it.
But the point wasn't that relations don't have labels, it was that for ANY entity type, there is no guarantee that it will have a label in the DB, or that if they do, that there'll be a way to know what table/column it's stored in.
Comment #41
alanom commented--- post edited after a bit more research --------------------
entity_get_info() names the table in ['base_table']. Label is slightly trickier, ['entity_keys']['label'] finds it if it's defined. For what to do when it's not defined, I'm looking at entity_label(), label callback in hook_entity_info(), and also how Entity Reference and also Entity Reference Field do this in their widgets.
It looks like the best way is to use entity_label() where possible with two tiers of fallback:
1) For the small number of entities with no labels we want to cover for (user already has a label callback on username, so that would be relation, maybe one or two more), a few fixes for generating specific entities using either hook_entity_info_alter() label callback or a case switch
2) For everything else, some standard formula based on mandatory keys. Most likely just entity label plus a lookup on the column named in the mandatory ['entity_keys']['id'] to create something equivalent to 'Relation [rid]' - not great, but these aren't common and represent pretty niche use cases for relations (Redirect is the only one I've found so far).
Comment #42
naught101 commentedYou can't search over entity_label(). You need a database column.
Of course, for user, the name column in the database is the label, so we can create a special case for that (I don't know why it's not in 'entity keys' in user_entity_info() though..).
Comment #43
naught101 commentedcrossreferencing: #1061688: Available entities browser
Comment #44
chx commentedThis is a big, big blocker.
People want a widget.
I can't provide a widget in a generic case. I can pile hacks on top of hacks. Problem is, I don't want to hack. I want a clean solution which is simply not possible with the D7 Entity API.
The widget is inappropriate anyways because the relation is not part of the entity.
Following, people dismiss the block I came up with as too complex.
I do not know how to continue with this module.
Comment #45
30equals commentedwasn't naught101 working on an embeddable block which provides the possibility to add a relation from the current entity ? i haven't looked into the details, but maybe it could be a starting point for a proper widget ?
http://drupal.org/sandbox/naught101/1275426
Comment #46
naught101 commentedNothing embeddable about that block. The form could probably be used by the widget though.
Comment #47
jherencia commentedComment #48
naught101 commentedPartly in order to get some good ideas about future UIs, it'd be good to get people's hopes and dreams for relations over here: #1282376: Brainstorm: What do you want out of relation?
Comment #49
ben_scott commentedHi -
I've been developing a relation field widget for my current project - http://drupal.org/project/relation_select. It acts as a drop down list & uses EFQ Views & exposed filters to select the entities. It's a work in progress so any feedback would be welcome.
Cheers,
Ben
Comment #50
klonosThanx for letting us know Ben. I'm heading there now and hopefully will be able to provide feedback soon.
Comment #51
naught101 commentedAfter a bit of discussion with chx, we've removed the widget. This is basically because it was pretty broken, and difficult to deal with. After seeing Ben's relation widget (in #49) we realised that the best path to take here would be to see what contrib can come up with (this is an API module, after all, UI is just a bonus). If someone comes up with a good solution that mimics a field widget, we'll consider merging it in to relation core.
So, closing this for now. In the mean time, you have two block-based UIs, (one that mimics a widget), and Ben's widget. If a new widget comes up that is looking really good, feel free to open a new issue to discuss putting it in relation core.
oh, and the kill commit was 232dc32, if anyone wants to take the old code and run with it in contrib.
Cheers
ned
Comment #52
chx commentedBen, as I did on Twitter let me thank you profusedly for getting the project out of a ditch by proving that people will write widgets for relation.
Comment #53
ben_scott commentedHey chx -
Glad I could help! Thank you for writing such a great module to build upon - it's completely changed the way we're building sites.
Cheers,
Ben
Comment #54
klonosThis issue needs an issue summary, so that people coming here know what was finally decided and why. I tried to do it, but I cannot fully grasp most of what was debated.
Ben's Relation Select project and #1282376: Brainstorm: What do you want out of relation? as well as any related articles/issues/projects should be mentioned there so that people know where to head to.
Comment #54.0
klonosMore details, including link, about Relation Select.
Comment #55
klonosThanx ned! That was fast ;)
Comment #56
joachim commentedJust a thought which I don't have the time to follow through, but how about using a widget based on Hierarchical Select when there are multiple entity types?
Ie:
[type dropdown] [entity name dropdown]
The way it works is that the content of the 2nd dropdown are only fetched once the first dropdown has been chosen, at which point you'd have a single entity query.
Comment #57
naught101 commentedWorth trying, although anything with a contrib dependency is less likely to get in to relation core.
Comment #58
BarisW commentedProbable a very horrible solution, but in my usecase it works.
Adding a 'label callback' in the hook_entity_info and this callback:
Comment #59
pkej commentedCould you create a patch for this?
Comment #59.0
pkej commentedUpdated issue summary.
Comment #60
davidburnsAuto Complete widget for relation.
https://drupal.org/sandbox/vordude/1814752