2 potential bugs, 1 report. Hope that's OK.

User: 1 (full privileges)
Drupal 6.15
Node Imprt 6.x-1.0-rc4
Node Reference Create (noderefcreate) 6.x-1.0
CCK 6.x-2.6
PHP 5.2.10-2ubuntu6.4

1) Strange behavior with node reference create

Have a Person content type with an "Institutional Affiliation" field that references an Institution content type. I created all of the Institutions before doing the import, the names all match 100%. When this Institutional Affiliation was set to Type: "Autocomplete text field with create" (using Node Reference Create module), Node Import created a new Institution for each person (with names "7" or "8" or "4", strangley enough) instead of referencing the original institutions.

Workaround: Change Node references type to select list before importing. Change back after the import.

2) Problems importing node references with similar names

Have two institutions: University of Michigan and University of Michigan Biological Station. Node references to "University of Michigan" work fine, node references to "University of Michigan Biological Station" fail and produce this error: "Institutional Affiliation: this post can't be referenced."

Workaround: Change the Institution name from "University of Michigan Biological Station" to "UMBS University of Michigan Biological Station" - and reflect this in my csv import - everything works fine.

Thanks for your work on this module.

Kyle

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

deltab’s picture

+ Subscribing, I am experiencing this too.

Vacilando’s picture

Subscribing.

Isostar’s picture

+1 subscribing

kbk’s picture

Title: Strange behavior with node reference create AND problems importing node references with similar names » Compatibility with Node Reference Create

I should never have posted two reports in the same issue. I've now moved point 2) to its own report: #993510: Problems importing node references with similar names. Please use this issue for problems related to 1) Compatibility with Node Reference Create.

If someone would like to remove 2) from the original post, please do so. Thanks and sorry.

kbk’s picture

Version: 6.x-1.0-rc4 » 6.x-1.x-dev
Category: bug » feature
FileSize
2.26 KB
172.28 KB
172.16 KB

I'm taking the liberty to look into this myself. I'm a total newb at php so we'll see how it goes. First, I am assuming the difference in the node add form for a content type with a normal NodeReference versus a NodeRefCreate field is the foundation of our problem. Here are the differences (from what I can gather):

Node reference with autocomplete:

[type] => [nodereference_autocomplete]
[module] => [nodereference]

Node reference create with autocomplete:

[type] => [noderefcreate_autocomplete]
[module] => [noderefcreate]

NodeRefCreate add something else to the form. I don't understand this at all and I hope it is inconsequential:

[#process] => array (
  [0] => [noderefcreate_autocomplete_process]
)

See attached for the the node add forms associated with my content type 'Person' with and without NodeRefCreate. The third file is a diff of the first two.

kbk’s picture

Looking at nodereference.inc there is this interesting portion:

/**
 * Implementation of hook_node_import_values_alter().
 */
function nodereference_node_import_values_alter(&$values, $type, $defaults, $options, $fields, $preview) {
  dpm($values);
  dpm($preview);
  foreach (node_import_cck_fields($type, 'nodereference') as $fieldname => $fieldinfo) {
    if ($fieldinfo['widget']['type'] == 'nodereference_autocomplete') {
      foreach ($values[$fieldname] as $i => $value) {
        // This is just braindead - because of some wrapper, the value
        // needs to be:
        // array(0 => array('nid' => array('nid' => 'name')))
        // instead of:
        // array(0 => array('nid' => 'name')).
        $values[$fieldname][$i]['nid'] = array('nid' => $values[$fieldname][$i]['nid']);
      }
    }
  }
}

dpm($form) shows that NodeRefCreate has the same 'braindead' structure.

kbk’s picture

Modifying the above test to:

  foreach (node_import_cck_fields($type, 'nodereference') as $fieldname => $fieldinfo) {
    if ($fieldinfo['widget']['type'] == 'nodereference_autocomplete' || $fieldinfo['widget']['type'] == 'noderefcreate_autocomplete') {

Improves matters a little. Without the test, Node Import creates a node where the Node Title is the first number of the NID (I'm using NIDs instead of Node Titles) in the imported file. Adding the test still results in a node being created (rather than referenced) but it at least uses the full NID.

kbk’s picture

In the event that the #process bit from #5 is actually important, it arises in noderefcreate.module:

function noderefcreate_widget(&$form, &$form_state, $field, $items, $delta = 0) {
  switch ($field['widget']['type']) {
    case 'noderefcreate_autocomplete':
      $element = array(
        '#type' => 'nodereference_autocomplete',
        '#default_value' => isset($items[$delta]) ? $items[$delta] : NULL,
        '#value_callback' => 'nodereference_autocomplete_value',
        '#process' => array('noderefcreate_autocomplete_process'),
      );
      break;
  }
  return $element;
}
kbk’s picture

Got it working - I think - and I am a bit frustrated because the solution seemed to rely on a patch that has been pending for 2 years.

Basically you would do as I did in #7 and use a patch from this issue: #403140: Error on autocomplete node reference field: found no valid post with that title.

I used this patch:
http://drupal.org/node/403140#comment-2309632

But this patch looks similar and is more recent:
http://drupal.org/node/403140#comment-2892098

Note: this will allow you to use NodeRefCreate when you are importing the NID, Node Title imports with NodeRefCreate are untested.

kbk’s picture

Status: Active » Needs review
FileSize
732 bytes

For Node Reference Create compatibility apply the attached patch to the dev version of Node Import and then apply the patch found here:

http://drupal.org/node/403140#comment-2892098

NOTE: This is tested when importing NID values, not Node Titles. There are several issues pending re: Node Title imports so it will be difficult to tell where the problem lies.