Closed (fixed)
Project:
Entityreference Autocreate
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
11 Nov 2013 at 13:01 UTC
Updated:
18 May 2016 at 22:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
dasjothe attached patch has been tested with entites based on the While module.
Comment #2
dman commentedThanks. This has been on the roadmap, but wasn't an itch I had time to scratch myself. I'd hoped there would be a graceful way to do it ...
Mmm. $label_key. That looks like what I was hoping to see.
Comment #3
dasjohi dman, glad you like it!
i haven't tested it with nodes, but i think it should pretty much work that way :)
Comment #4
dman commentedTesting... (half notes-to-self) my drush-iq utility is broken since the d.o upgrade so..
..
* using an existing site, haf-populated with entityrefs already...
* Add a new entityref field to a content type. This time to a 'user' entity, why not... with an 'autocomplete' widget.
* Target selection 'simple'
* Autocreate target if not found
* Edited an existing node, entered 'John' as the user to see if it would create a user for me = There are no entities matching "John"
* So that validation is not being skipped. :-(
Try again - maybe it will work on taxonomies (although they already support 'tag' style autocomplete natively, I should be able to double it up with an entityreference way of handling it - if we now have generic 'entity' support ...
Soo, it tried to make a term but with an unknown vid. That's not allowed so it failed. Unhappily and broke.
Looks like we need to take lots of care and special cases for each entity out there, there may not be a one-size-fits-all "make me a thing" solution here.
So far the other core entities, taxonomy term and user have both totally failed. It may be that we don't *expect* to have to use this utility on those entities, but if we can't get those right, how can we expect arbitrary contrib entities to work any more reliably?
Comment #5
dasjothe problem is that core entities aren't build in a uniform, reusable way as entity api entities are. so you'll need special coding like #2053789: Add support for entity type taxonomy for those.
the above patch should still work for most custom entities that can be created without requiring any special information.
my suggestions is to define optional callbacks for the entity creation based on the entity type.
you can then provide the necessary callbacks for the core entities and leave it up to contrib modules to provide creation callbacks for themselves. in the case of the while entity this isn't needed as it doesn't need any further parameters.
Comment #6
fagoPatch looks good. Not necessarily part of this issue, but the module should respect all entity keys and apply bundle and language keys also.
Comment #7
fagoBundles for terms are problematic yep. I guess we could provide a creation callback for terms in entity api that sets the 'vid' if at least the bundle is specified.
Comment #8
dman commentedI can't get this in while it dies so badly on just the core entities ... So I merged part of #2053789: Add support for entity type taxonomy in and added partial user support to the point where they don't break.
I tried it on another random contrib entity (wsclient) and discovered new problems, (though I don't expect there to be any sane reason you'd want to refer to a wsclient, it does seem that it demonstrates that all entities are inconsistent.
We can add a hook callback in there for the hell of it, maybe as sketched out in #2053789: Add support for entity type taxonomy - though it should be a Drupal hook callback, not a hook_alter. But I really don't expect any contribs to start doing that for us.
Comment #9
dman commentedComment #10
dasjoi think we really should use the
entity_create()function instead of(object) array ....so i suggest preparing the values within the switch statement (or ideally moving that logic to a callback) and afterwards properly create the entities.
Comment #11
fagoyes. entity-saving stdclass objects won't work with entity types that use classes
Comment #12
dman commentedYay. It's new core function names like that I wasn't even aware of when I first threw this together :-)
Comment #13
dman commentedAh boo. Well this is why.
It would introduce a dependency on entity API module - which isn't yet needed.
I've got nothing *against* EntityAPI ... but I dislike including a whole module just to use one convenience function .... Needs thinking about.
If EntityAPI also provides better validation and default value management and error handling for creating stubs - then yep.
Otherwise it's currently not-broken using (object) ... unless someone can give an example where this really fails?
Comment #14
dasjoNote that entityreference already depends on entity api, so that shouldn't be an issue :)
Comment #15
dman commentedAh Righty then :-) Thanks!
Comment #16
bennos commentedPatch in #8 works for taxonomy. No problems with Taxonomy term (autocomplete widget and autocomplete tag style widget.
Comment #17
dman commentedAges later, I got a bump on this project.
I've now merged all the above bits into dev, and some significant refactoring in too, based on some of the hints from the above issue.
Trialled with nodes, taxonomy, users (it looks like it was just them that was the major spanner in the works) as well as "while" entities (they are cute - I'd not followed up the first reference to them because it sounded like some timekeeping app I didn't really want to try out)
So far so good. I've been able to rapidly make vast networks of references, and seem to have eliminated a few rough corners also.
I've put it right into -dev because I was fixing up lots of stuff and didn;t want to lose everything again for another six months.
Thanks for everyones input above!
Comment #18
Yuri commentedThe patch #9 doesn't patch any more.
Comment #19
dman commentedThe patch from 2013 won't apply, as in comment #17 most of the things it did were merged into -dev in 2014.
The system now *attempts* to do support of arbitrary entities (can do users, probably ECK things, and I think field_collections) but we also know that different entities are different.
So: 'fixed' to the point where it works, but not to where it's sure to always sure to work.
If you have a use-case to test against a specific new entity type, please open a new issue, with details how to replicate.