Suppose someone creates a node reference field that allows multiple content types to be referenced. When noderefcreate_autocomplete_validate() executes and tries to create a new node how does it know which content type to use? Right now the code pulls up an array of potential references but then seems to arbitrarily select the last content type in the array. In the code below $reference is an array of content types but $newnode->type is set to the last $field['referenceable_types'].
function noderefcreate_autocomplete_validate($element, &$form_state) {
//...
$reference = _nodereference_potential_references($field, $value, 'equals', NULL, 1);
if (empty($reference)) {
$newnode = NULL;
if (is_array($field['referenceable_types'])) {
foreach (array_filter($field['referenceable_types']) as $related_type) {
$newnode->type = $related_type;
}
}
Seems like one of the following should occur:
- the end user could select a content type to create
- a default content type could be set when the node reference field is defined
- the field should be limited to one content type
Does anyone use a node reference field that lists multiple content types? Am I just missing something here?
Comments
Comment #1
jwilson3Sounds like an interesting but unique use case, and should probably be a feature request, not necessarily a bug report.
Comment #2
wolf_22 commentedFeature request or not, there should be something a bit more deliberately-emphasized within the NRC UI to prevent users from being led to believe it can use core functionality if it cannot. But for whatever it's worth (and unless I'm misunderstanding something here), I just did the following to test all this:
1.) I created 3 content types: Content Type A (with a CNR field referencing the following content types), Content Type B, and Content Type C.
2.) I then created a basic Content Type B and C node (with titles aptly named 'B' and 'C', respectively).
3.) I created a Content Type A page and attempted to type 'B' into it and voila, it popped-up with 'B' being a "referenceable" node. Did the same with 'C' and had no problems.
BUT, this was obviously a very generic test. I'm not sure if there might be problems with more extensive setups... So use your own judgment...
Comment #3
dago.aceves commentedWolf_22 have you taken a look at Inline Entity Form?
http://drupal.org/project/inline_entity_form
Comment #4
wolf_22 commenteddago.aceves, if someone is using Drupal 7 and attempting to create an referencing field that can create / edit if no referenceable content exists, they should be using Entity Connect--not Node Reference Create.
For a functionally ubiquitous form setup, you'll want to use a culmination of the following:
1.) Entity API
2.) Entity Reference
3.) Entity Connect
4.) Corresponding Entity Reference
I know everyone has their own business requirements, but using those modules, you'll have back-referencing and sub-node create/edit on parent node add / edit pages. It's going to be pretty hard to beat this (and I've tested and verified that these all work with each other.)
The buggiest of those above is Corresponding Entity Reference, but it still works... It just has some Warnings / Notices right now with the current version they're working on.